Ensure sync thread is started when recovering from crash.

This commit is contained in:
Benoit Marty 2023-01-27 16:44:35 +01:00
parent 366ce8665d
commit 5a62e31c86
2 changed files with 42 additions and 0 deletions

View file

@ -0,0 +1,38 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.app.core.session
import android.content.Context
import dagger.hilt.android.qualifiers.ApplicationContext
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.extensions.startSyncing
import org.matrix.android.sdk.api.session.sync.SyncState
import timber.log.Timber
import javax.inject.Inject
class EnsureSessionSyncingUseCase @Inject constructor(
@ApplicationContext private val context: Context,
private val activeSessionHolder: ActiveSessionHolder,
) {
fun execute() {
val session = activeSessionHolder.getSafeActiveSession() ?: return
if (session.syncService().getSyncState() == SyncState.Idle) {
Timber.w("EnsureSessionSyncingUseCase: start syncing")
session.startSyncing(context)
}
}
}

View file

@ -30,6 +30,7 @@ import im.vector.app.core.pushers.EnsureFcmTokenIsRetrievedUseCase
import im.vector.app.core.pushers.PushersManager
import im.vector.app.core.pushers.RegisterUnifiedPushUseCase
import im.vector.app.core.pushers.UnregisterUnifiedPushUseCase
import im.vector.app.core.session.EnsureSessionSyncingUseCase
import im.vector.app.features.analytics.AnalyticsConfig
import im.vector.app.features.analytics.AnalyticsTracker
import im.vector.app.features.analytics.extensions.toAnalyticsType
@ -95,6 +96,7 @@ class HomeActivityViewModel @AssistedInject constructor(
private val registerUnifiedPushUseCase: RegisterUnifiedPushUseCase,
private val unregisterUnifiedPushUseCase: UnregisterUnifiedPushUseCase,
private val ensureFcmTokenIsRetrievedUseCase: EnsureFcmTokenIsRetrievedUseCase,
private val ensureSessionSyncingUseCase: EnsureSessionSyncingUseCase,
) : VectorViewModel<HomeActivityViewState, HomeActivityViewActions, HomeActivityViewEvents>(initialState) {
@AssistedFactory
@ -118,6 +120,8 @@ class HomeActivityViewModel @AssistedInject constructor(
private fun initialize() {
if (isInitialized) return
isInitialized = true
// Ensure Session is syncing
ensureSessionSyncingUseCase.execute()
registerUnifiedPushIfNeeded()
cleanupFiles()
observeInitialSync()