Fix sync thread sometimes not running

Change-Id: Icdfb56a5eba4d779047e67c99761d333bb4457a5
This commit is contained in:
SpiritCroc 2022-08-03 17:48:00 +02:00
parent d713a782b0
commit 46e265d490
1 changed files with 10 additions and 1 deletions

View File

@ -20,6 +20,7 @@ import android.content.Context
import arrow.core.Option import arrow.core.Option
import im.vector.app.ActiveSessionDataSource import im.vector.app.ActiveSessionDataSource
import im.vector.app.core.extensions.configureAndStart import im.vector.app.core.extensions.configureAndStart
import im.vector.app.core.extensions.startSyncing
import im.vector.app.core.pushers.UnifiedPushHelper import im.vector.app.core.pushers.UnifiedPushHelper
import im.vector.app.core.services.GuardServiceStarter import im.vector.app.core.services.GuardServiceStarter
import im.vector.app.features.call.webrtc.WebRtcCallManager import im.vector.app.features.call.webrtc.WebRtcCallManager
@ -30,6 +31,7 @@ import im.vector.app.features.session.SessionListener
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import org.matrix.android.sdk.api.auth.AuthenticationService import org.matrix.android.sdk.api.auth.AuthenticationService
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 timber.log.Timber import timber.log.Timber
import java.util.concurrent.atomic.AtomicReference import java.util.concurrent.atomic.AtomicReference
import javax.inject.Inject import javax.inject.Inject
@ -100,7 +102,14 @@ class ActiveSessionHolder @Inject constructor(
} }
suspend fun getOrInitializeSession(startSync: Boolean): Session? { suspend fun getOrInitializeSession(startSync: Boolean): Session? {
return activeSessionReference.get() ?: sessionInitializer.tryInitialize(readCurrentSession = { activeSessionReference.get() }) { session -> return activeSessionReference.get()?.also { session ->
val syncState = session.syncService().getSyncState()
Timber.i("SC-SYNC-0803 session existed already; $syncState") // SC-TODO clean up
if (startSync && syncState == SyncState.Idle) {
session.startSyncing(applicationContext)
}
} ?: sessionInitializer.tryInitialize(readCurrentSession = { activeSessionReference.get() }) { session ->
Timber.i("SC-SYNC-0803 getOrInitializeSession new session $startSync") // SC-TODO clean up
setActiveSession(session) setActiveSession(session)
session.configureAndStart(applicationContext, startSyncing = startSync) session.configureAndStart(applicationContext, startSyncing = startSync)
} }