Merge pull request #1587 from vector-im/feature/fix_sync

Sync: fix liveState not initialized and add method to get current sta…
This commit is contained in:
Benoit Marty 2020-07-01 13:27:48 +02:00 committed by GitHub
commit 8adb36c7c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 7 deletions

View file

@ -127,6 +127,12 @@ interface Session :
*/
fun getSyncStateLive(): LiveData<SyncState>
/**
* This method returns the current sync state.
* @return the current [SyncState].
*/
fun getSyncState(): SyncState
/**
* This methods return true if an initial sync has been processed
*/

View file

@ -17,7 +17,6 @@
package im.vector.matrix.android.internal.session
import androidx.annotation.MainThread
import androidx.lifecycle.LiveData
import dagger.Lazy
import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.auth.data.SessionParams
@ -45,7 +44,6 @@ import im.vector.matrix.android.api.session.securestorage.SecureStorageService
import im.vector.matrix.android.api.session.securestorage.SharedSecretStorageService
import im.vector.matrix.android.api.session.signout.SignOutService
import im.vector.matrix.android.api.session.sync.FilterService
import im.vector.matrix.android.api.session.sync.SyncState
import im.vector.matrix.android.api.session.terms.TermsService
import im.vector.matrix.android.api.session.typing.TypingUsersTracker
import im.vector.matrix.android.api.session.user.UserService
@ -197,9 +195,9 @@ internal class DefaultSession @Inject constructor(
eventBus.unregister(this)
}
override fun getSyncStateLive(): LiveData<SyncState> {
return getSyncThread().liveState()
}
override fun getSyncStateLive() = getSyncThread().liveState()
override fun getSyncState() = getSyncThread().currentState()
override fun hasAlreadySynced(): Boolean {
return syncTokenStore.getLastToken() != null

View file

@ -104,7 +104,7 @@ abstract class SyncService : Service() {
try {
syncTask.execute(params)
// Start sync if we were doing an initial sync and the syncThread is not launched yet
if (isInitialSync && session.getSyncStateLive().value == SyncState.Idle) {
if (isInitialSync && session.getSyncState() == SyncState.Idle) {
val isForeground = !backgroundDetectionObserver.isInBackground
session.startSync(isForeground)
}

View file

@ -51,7 +51,7 @@ internal class SyncThread @Inject constructor(private val syncTask: SyncTask,
: Thread(), NetworkConnectivityChecker.Listener, BackgroundDetectionObserver.Listener {
private var state: SyncState = SyncState.Idle
private var liveState = MutableLiveData<SyncState>()
private var liveState = MutableLiveData<SyncState>(state)
private val lock = Object()
private val syncScope = CoroutineScope(SupervisorJob())
private val debouncer = Debouncer(createUIHandler())
@ -98,6 +98,8 @@ internal class SyncThread @Inject constructor(private val syncTask: SyncTask,
lock.notify()
}
fun currentState() = state
fun liveState(): LiveData<SyncState> {
return liveState
}