diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/sync/SyncService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/sync/SyncService.kt index 5b2bf651af..d924b04802 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/sync/SyncService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/sync/SyncService.kt @@ -21,6 +21,9 @@ import kotlinx.coroutines.flow.SharedFlow import org.matrix.android.sdk.api.session.sync.model.SyncResponse interface SyncService { + + suspend fun syncOnce(timeout: Long): SyncResponse + /** * This method start the sync thread. */ diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/DefaultSyncService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/DefaultSyncService.kt index 37869b88f9..e474daeb73 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/DefaultSyncService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/DefaultSyncService.kt @@ -17,8 +17,15 @@ package org.matrix.android.sdk.internal.session.sync import androidx.lifecycle.LiveData +import io.realm.RealmConfiguration +import org.matrix.android.sdk.api.MatrixCoroutineDispatchers import org.matrix.android.sdk.api.session.sync.SyncRequestState import org.matrix.android.sdk.api.session.sync.SyncService +import org.matrix.android.sdk.api.session.sync.model.SyncResponse +import org.matrix.android.sdk.internal.database.awaitNotEmptyResult +import org.matrix.android.sdk.internal.database.model.SyncEntity +import org.matrix.android.sdk.internal.database.model.SyncEntityFields +import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.di.SessionId import org.matrix.android.sdk.internal.di.WorkManagerProvider import org.matrix.android.sdk.internal.session.SessionState @@ -35,7 +42,9 @@ internal class DefaultSyncService @Inject constructor( private val syncTokenStore: SyncTokenStore, private val syncRequestStateTracker: SyncRequestStateTracker, private val sessionState: SessionState, + private val syncTask: SyncTask, ) : SyncService { + private var syncThread: SyncThread? = null override fun requireBackgroundSync() { @@ -50,6 +59,11 @@ internal class DefaultSyncService @Inject constructor( SyncWorker.stopAnyBackgroundSync(workManagerProvider) } + override suspend fun syncOnce(timeout: Long): SyncResponse { + val syncParams = SyncTask.Params(timeout = timeout, presence = null, afterPause = false) + return syncTask.execute(syncParams) + } + override fun startSync(fromForeground: Boolean) { Timber.i("Starting sync thread") assert(sessionState.isOpen)