Sync: add syncOnce method

This commit is contained in:
ganfra 2022-07-11 19:06:34 +02:00
parent 8a68b31f1b
commit 4c2b28075c
2 changed files with 17 additions and 0 deletions

View File

@ -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.
*/

View File

@ -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)