mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-24 18:36:21 +03:00
Don't set presence when handling a push notification or polling (#2156)
This commit is contained in:
parent
17d1a4b6fb
commit
79d7032e3a
6 changed files with 44 additions and 5 deletions
|
@ -29,6 +29,7 @@ Bugfix 🐛:
|
||||||
- Simplifies draft management and should fix bunch of draft issues (#952, #683)
|
- Simplifies draft management and should fix bunch of draft issues (#952, #683)
|
||||||
- Very long topic cannot be fully visible (#1957)
|
- Very long topic cannot be fully visible (#1957)
|
||||||
- Properly detect cross signing keys reset
|
- Properly detect cross signing keys reset
|
||||||
|
- Don't set presence when handling a push notification or polling (#2156)
|
||||||
|
|
||||||
Translations 🗣:
|
Translations 🗣:
|
||||||
- Move store data to `/fastlane/metadata/android` (#812)
|
- Move store data to `/fastlane/metadata/android` (#812)
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.matrix.android.sdk.internal.session.sync
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For `set_presence` parameter in the /sync request
|
||||||
|
*
|
||||||
|
* Controls whether the client is automatically marked as online by polling this API. If this parameter
|
||||||
|
* is omitted then the client is automatically marked as online when it uses this API. Otherwise if the
|
||||||
|
* parameter is set to "offline" then the client is not marked as being online when it uses this API.
|
||||||
|
* When set to "unavailable", the client is marked as being idle. One of: ["offline", "online", "unavailable"]
|
||||||
|
*/
|
||||||
|
enum class SyncPresence(val value: String) {
|
||||||
|
Offline("offline"),
|
||||||
|
Online("online"),
|
||||||
|
Unavailable("unavailable")
|
||||||
|
}
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package org.matrix.android.sdk.internal.session.sync
|
package org.matrix.android.sdk.internal.session.sync
|
||||||
|
|
||||||
|
import org.greenrobot.eventbus.EventBus
|
||||||
import org.matrix.android.sdk.R
|
import org.matrix.android.sdk.R
|
||||||
import org.matrix.android.sdk.internal.di.UserId
|
import org.matrix.android.sdk.internal.di.UserId
|
||||||
import org.matrix.android.sdk.internal.network.executeRequest
|
import org.matrix.android.sdk.internal.network.executeRequest
|
||||||
|
@ -25,13 +26,15 @@ import org.matrix.android.sdk.internal.session.homeserver.GetHomeServerCapabilit
|
||||||
import org.matrix.android.sdk.internal.session.sync.model.SyncResponse
|
import org.matrix.android.sdk.internal.session.sync.model.SyncResponse
|
||||||
import org.matrix.android.sdk.internal.session.user.UserStore
|
import org.matrix.android.sdk.internal.session.user.UserStore
|
||||||
import org.matrix.android.sdk.internal.task.Task
|
import org.matrix.android.sdk.internal.task.Task
|
||||||
import org.greenrobot.eventbus.EventBus
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
internal interface SyncTask : Task<SyncTask.Params, Unit> {
|
internal interface SyncTask : Task<SyncTask.Params, Unit> {
|
||||||
|
|
||||||
data class Params(var timeout: Long = 6_000L)
|
data class Params(
|
||||||
|
val timeout: Long,
|
||||||
|
val presence: SyncPresence?
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class DefaultSyncTask @Inject constructor(
|
internal class DefaultSyncTask @Inject constructor(
|
||||||
|
@ -63,6 +66,7 @@ internal class DefaultSyncTask @Inject constructor(
|
||||||
}
|
}
|
||||||
requestParams["timeout"] = timeout.toString()
|
requestParams["timeout"] = timeout.toString()
|
||||||
requestParams["filter"] = filterRepository.getFilter()
|
requestParams["filter"] = filterRepository.getFilter()
|
||||||
|
params.presence?.let { requestParams["set_presence"] = it.value }
|
||||||
|
|
||||||
val isInitialSync = token == null
|
val isInitialSync = token == null
|
||||||
if (isInitialSync) {
|
if (isInitialSync) {
|
||||||
|
|
|
@ -30,6 +30,7 @@ import org.matrix.android.sdk.api.failure.isTokenError
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.sync.SyncState
|
import org.matrix.android.sdk.api.session.sync.SyncState
|
||||||
import org.matrix.android.sdk.internal.network.NetworkConnectivityChecker
|
import org.matrix.android.sdk.internal.network.NetworkConnectivityChecker
|
||||||
|
import org.matrix.android.sdk.internal.session.sync.SyncPresence
|
||||||
import org.matrix.android.sdk.internal.session.sync.SyncTask
|
import org.matrix.android.sdk.internal.session.sync.SyncTask
|
||||||
import org.matrix.android.sdk.internal.task.TaskExecutor
|
import org.matrix.android.sdk.internal.task.TaskExecutor
|
||||||
import org.matrix.android.sdk.internal.util.BackgroundDetectionObserver
|
import org.matrix.android.sdk.internal.util.BackgroundDetectionObserver
|
||||||
|
@ -147,7 +148,7 @@ abstract class SyncService : Service() {
|
||||||
|
|
||||||
private suspend fun doSync() {
|
private suspend fun doSync() {
|
||||||
Timber.v("## Sync: Execute sync request with timeout $syncTimeoutSeconds seconds")
|
Timber.v("## Sync: Execute sync request with timeout $syncTimeoutSeconds seconds")
|
||||||
val params = SyncTask.Params(syncTimeoutSeconds * 1000L)
|
val params = SyncTask.Params(syncTimeoutSeconds * 1000L, SyncPresence.Offline)
|
||||||
try {
|
try {
|
||||||
// never do that in foreground, let the syncThread work
|
// never do that in foreground, let the syncThread work
|
||||||
syncTask.execute(params)
|
syncTask.execute(params)
|
||||||
|
|
|
@ -38,6 +38,7 @@ import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.matrix.android.sdk.api.session.call.MxCall
|
import org.matrix.android.sdk.api.session.call.MxCall
|
||||||
import org.matrix.android.sdk.internal.session.call.ActiveCallHandler
|
import org.matrix.android.sdk.internal.session.call.ActiveCallHandler
|
||||||
|
import org.matrix.android.sdk.internal.session.sync.SyncPresence
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.net.SocketTimeoutException
|
import java.net.SocketTimeoutException
|
||||||
import java.util.Timer
|
import java.util.Timer
|
||||||
|
@ -161,7 +162,7 @@ internal class SyncThread @Inject constructor(private val syncTask: SyncTask,
|
||||||
// No timeout after a pause
|
// No timeout after a pause
|
||||||
val timeout = state.let { if (it is SyncState.Running && it.afterPause) 0 else DEFAULT_LONG_POOL_TIMEOUT }
|
val timeout = state.let { if (it is SyncState.Running && it.afterPause) 0 else DEFAULT_LONG_POOL_TIMEOUT }
|
||||||
Timber.v("Execute sync request with timeout $timeout")
|
Timber.v("Execute sync request with timeout $timeout")
|
||||||
val params = SyncTask.Params(timeout)
|
val params = SyncTask.Params(timeout, SyncPresence.Online)
|
||||||
val sync = syncScope.launch {
|
val sync = syncScope.launch {
|
||||||
doSync(params)
|
doSync(params)
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.matrix.android.sdk.api.failure.isTokenError
|
||||||
import org.matrix.android.sdk.internal.di.WorkManagerProvider
|
import org.matrix.android.sdk.internal.di.WorkManagerProvider
|
||||||
import org.matrix.android.sdk.internal.network.NetworkConnectivityChecker
|
import org.matrix.android.sdk.internal.network.NetworkConnectivityChecker
|
||||||
import org.matrix.android.sdk.internal.session.SessionComponent
|
import org.matrix.android.sdk.internal.session.SessionComponent
|
||||||
|
import org.matrix.android.sdk.internal.session.sync.SyncPresence
|
||||||
import org.matrix.android.sdk.internal.session.sync.SyncTask
|
import org.matrix.android.sdk.internal.session.sync.SyncTask
|
||||||
import org.matrix.android.sdk.internal.task.TaskExecutor
|
import org.matrix.android.sdk.internal.task.TaskExecutor
|
||||||
import org.matrix.android.sdk.internal.worker.SessionSafeCoroutineWorker
|
import org.matrix.android.sdk.internal.worker.SessionSafeCoroutineWorker
|
||||||
|
@ -94,7 +95,7 @@ internal class SyncWorker(context: Context,
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun doSync(timeout: Long) {
|
private suspend fun doSync(timeout: Long) {
|
||||||
val taskParams = SyncTask.Params(timeout * 1000)
|
val taskParams = SyncTask.Params(timeout * 1000, SyncPresence.Offline)
|
||||||
syncTask.execute(taskParams)
|
syncTask.execute(taskParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue