mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Ensure sync thread is started when recovering from crash.
This commit is contained in:
parent
366ce8665d
commit
5a62e31c86
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user