lifting the sync timeout to the matrix configuration

This commit is contained in:
Adam Brown 2022-09-21 14:25:26 +01:00
parent d31d833959
commit 7f31098ba1
3 changed files with 32 additions and 3 deletions

View File

@ -70,4 +70,8 @@ data class MatrixConfiguration(
* List of network interceptors, they will be added when building an OkHttp client.
*/
val networkInterceptors: List<Interceptor> = emptyList(),
/**
* Sync configuration.
*/
val syncConfig: SyncConfig = SyncConfig()
)

View File

@ -0,0 +1,24 @@
/*
* Copyright 2022 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.api
data class SyncConfig(
/**
* Time to keep sync connection alive for before making another request in milliseconds.
*/
val longPollTimeout: Long = 30_000L
)

View File

@ -30,6 +30,7 @@ import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.matrix.android.sdk.api.MatrixConfiguration
import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.failure.Failure
import org.matrix.android.sdk.api.failure.isTokenError
@ -52,7 +53,6 @@ import javax.inject.Inject
import kotlin.concurrent.schedule
private const val RETRY_WAIT_TIME_MS = 10_000L
private const val DEFAULT_LONG_POOL_TIMEOUT = 30_000L
private val loggerTag = LoggerTag("SyncThread", LoggerTag.SYNC)
@ -61,7 +61,8 @@ internal class SyncThread @Inject constructor(
private val networkConnectivityChecker: NetworkConnectivityChecker,
private val backgroundDetectionObserver: BackgroundDetectionObserver,
private val activeCallHandler: ActiveCallHandler,
private val lightweightSettingsStorage: DefaultLightweightSettingsStorage
private val lightweightSettingsStorage: DefaultLightweightSettingsStorage,
private val matrixConfiguration: MatrixConfiguration,
) : Thread("Matrix-SyncThread"), NetworkConnectivityChecker.Listener, BackgroundDetectionObserver.Listener {
private var state: SyncState = SyncState.Idle
@ -181,7 +182,7 @@ internal class SyncThread @Inject constructor(
val timeout = when {
previousSyncResponseHasToDevice -> 0L /* Force timeout to 0 */
afterPause -> 0L /* No timeout after a pause */
else -> DEFAULT_LONG_POOL_TIMEOUT
else -> matrixConfiguration.syncConfig.longPollTimeout
}
Timber.tag(loggerTag.value).d("Execute sync request with timeout $timeout")
val presence = lightweightSettingsStorage.getSyncPresenceStatus()