mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-16 20:10:04 +03:00
delaying the first sync until the first process onStart event
- fixes push notifications starting the polling sync thread when the application is created due to push
This commit is contained in:
parent
7088e5cf54
commit
b7a54ead68
2 changed files with 19 additions and 3 deletions
|
@ -43,6 +43,7 @@ import im.vector.app.core.di.DaggerVectorComponent
|
|||
import im.vector.app.core.di.HasVectorInjector
|
||||
import im.vector.app.core.di.VectorComponent
|
||||
import im.vector.app.core.extensions.configureAndStart
|
||||
import im.vector.app.core.extensions.startSyncing
|
||||
import im.vector.app.core.rx.RxConfig
|
||||
import im.vector.app.features.call.webrtc.WebRtcCallManager
|
||||
import im.vector.app.features.configuration.VectorConfiguration
|
||||
|
@ -162,11 +163,15 @@ class VectorApplication :
|
|||
// Do not display the name change popup
|
||||
doNotShowDisclaimerDialog(this)
|
||||
}
|
||||
|
||||
if (authenticationService.hasAuthenticatedSessions() && !activeSessionHolder.hasActiveSession()) {
|
||||
val lastAuthenticatedSession = authenticationService.getLastAuthenticatedSession()!!
|
||||
activeSessionHolder.setActiveSession(lastAuthenticatedSession)
|
||||
lastAuthenticatedSession.configureAndStart(applicationContext)
|
||||
lastAuthenticatedSession.configureAndStart(applicationContext, startSyncing = false)
|
||||
}
|
||||
|
||||
ProcessLifecycleOwner.get().lifecycle.addObserver(startSyncOnFirstStart)
|
||||
|
||||
ProcessLifecycleOwner.get().lifecycle.addObserver(object : LifecycleObserver {
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
||||
fun entersForeground() {
|
||||
|
@ -199,6 +204,15 @@ class VectorApplication :
|
|||
EmojiManager.install(GoogleEmojiProvider())
|
||||
}
|
||||
|
||||
private val startSyncOnFirstStart = object : LifecycleObserver {
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
||||
fun onStart() {
|
||||
Timber.i("App process started")
|
||||
authenticationService.getLastAuthenticatedSession()?.startSyncing(appContext)
|
||||
ProcessLifecycleOwner.get().lifecycle.removeObserver(this)
|
||||
}
|
||||
}
|
||||
|
||||
private fun enableStrictModeIfNeeded() {
|
||||
if (BuildConfig.ENABLE_STRICT_MODE_LOGS) {
|
||||
StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder()
|
||||
|
|
|
@ -26,11 +26,13 @@ import org.matrix.android.sdk.api.session.crypto.keysbackup.KeysBackupState
|
|||
import org.matrix.android.sdk.api.session.sync.FilterService
|
||||
import timber.log.Timber
|
||||
|
||||
fun Session.configureAndStart(context: Context) {
|
||||
fun Session.configureAndStart(context: Context, startSyncing: Boolean = true) {
|
||||
Timber.i("Configure and start session for $myUserId")
|
||||
open()
|
||||
setFilter(FilterService.FilterPreset.ElementFilter)
|
||||
startSyncing(context)
|
||||
if (startSyncing) {
|
||||
startSyncing(context)
|
||||
}
|
||||
refreshPushers()
|
||||
context.vectorComponent().webRtcCallManager().checkForProtocolsSupportIfNeeded()
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue