mirror of
https://github.com/element-hq/element-android
synced 2024-11-23 18:05:36 +03:00
Fix #6782. Ensure SyncThread is started
This commit is contained in:
parent
f5104c7511
commit
0b1b228524
3 changed files with 18 additions and 4 deletions
|
@ -53,6 +53,11 @@ interface SyncService {
|
|||
*/
|
||||
fun getSyncState(): SyncState
|
||||
|
||||
/**
|
||||
* This method returns true if the sync thread is alive, i.e. started.
|
||||
*/
|
||||
fun isSyncThreadAlive(): Boolean
|
||||
|
||||
/**
|
||||
* This method allows to listen the sync state.
|
||||
* @return a [LiveData] of [SyncState].
|
||||
|
|
|
@ -73,6 +73,8 @@ internal class DefaultSyncService @Inject constructor(
|
|||
|
||||
override fun getSyncState() = getSyncThread().currentState()
|
||||
|
||||
override fun isSyncThreadAlive() = getSyncThread().isAlive
|
||||
|
||||
override fun getSyncRequestStateFlow() = syncRequestStateTracker.syncRequestState
|
||||
|
||||
override fun hasAlreadySynced(): Boolean {
|
||||
|
|
|
@ -20,6 +20,7 @@ import android.content.Context
|
|||
import arrow.core.Option
|
||||
import im.vector.app.ActiveSessionDataSource
|
||||
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.services.GuardServiceStarter
|
||||
import im.vector.app.features.call.webrtc.WebRtcCallManager
|
||||
|
@ -100,10 +101,16 @@ class ActiveSessionHolder @Inject constructor(
|
|||
}
|
||||
|
||||
suspend fun getOrInitializeSession(startSync: Boolean): Session? {
|
||||
return activeSessionReference.get() ?: sessionInitializer.tryInitialize(readCurrentSession = { activeSessionReference.get() }) { session ->
|
||||
setActiveSession(session)
|
||||
session.configureAndStart(applicationContext, startSyncing = startSync)
|
||||
}
|
||||
return activeSessionReference.get()
|
||||
?.also {
|
||||
if (startSync && !it.syncService().isSyncThreadAlive()) {
|
||||
it.startSyncing(applicationContext)
|
||||
}
|
||||
}
|
||||
?: sessionInitializer.tryInitialize(readCurrentSession = { activeSessionReference.get() }) { session ->
|
||||
setActiveSession(session)
|
||||
session.configureAndStart(applicationContext, startSyncing = startSync)
|
||||
}
|
||||
}
|
||||
|
||||
fun isWaitingForSessionInitialization() = activeSessionReference.get() == null && authenticationService.hasAuthenticatedSessions()
|
||||
|
|
Loading…
Reference in a new issue