mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 10:25:35 +03:00
separating the stopping of in-flight tasks form the cleaning up of the session state
- by stopping the session tasks before invalidating the current session we're able to avoid any extra token failures which retrigger the signout flow
This commit is contained in:
parent
52731cf59d
commit
2d1aed1839
4 changed files with 21 additions and 7 deletions
|
@ -51,6 +51,13 @@ internal class SessionManager @Inject constructor(private val matrixComponent: M
|
|||
}
|
||||
}
|
||||
|
||||
fun stopSession(sessionId: String) {
|
||||
if (sessionComponents.containsKey(sessionId).not()) {
|
||||
throw RuntimeException("You don't have a session for id $sessionId")
|
||||
}
|
||||
sessionComponents[sessionId]!!.session().stopSync()
|
||||
}
|
||||
|
||||
fun getOrCreateSessionComponent(sessionParams: SessionParams): SessionComponent {
|
||||
return sessionComponents.getOrPut(sessionParams.credentials.sessionId()) {
|
||||
DaggerSessionComponent
|
||||
|
|
|
@ -44,7 +44,7 @@ internal class DefaultDeactivateAccountTask @Inject constructor(
|
|||
|
||||
override suspend fun execute(params: DeactivateAccountTask.Params) {
|
||||
val deactivateAccountParams = DeactivateAccountParams.create(params.userAuthParam, params.eraseAllData)
|
||||
|
||||
cleanupSession.stopActiveTasks()
|
||||
val canCleanup = try {
|
||||
executeRequest(globalErrorReceiver) {
|
||||
accountAPI.deactivate(deactivateAccountParams)
|
||||
|
@ -71,7 +71,7 @@ internal class DefaultDeactivateAccountTask @Inject constructor(
|
|||
runCatching { identityDisconnectTask.execute(Unit) }
|
||||
.onFailure { Timber.w(it, "Unable to disconnect identity server") }
|
||||
|
||||
cleanupSession.handle()
|
||||
cleanupSession.cleanup()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,14 +50,20 @@ internal class CleanupSession @Inject constructor(
|
|||
@CryptoDatabase private val realmCryptoConfiguration: RealmConfiguration,
|
||||
@UserMd5 private val userMd5: String
|
||||
) {
|
||||
suspend fun handle() {
|
||||
|
||||
fun stopActiveTasks() {
|
||||
Timber.d("Cleanup: cancel pending works...")
|
||||
workManagerProvider.cancelAllWorks()
|
||||
|
||||
Timber.d("Cleanup: stop session...")
|
||||
sessionManager.stopSession(sessionId)
|
||||
}
|
||||
|
||||
suspend fun cleanup() {
|
||||
val sessionRealmCount = Realm.getGlobalInstanceCount(realmSessionConfiguration)
|
||||
val cryptoRealmCount = Realm.getGlobalInstanceCount(realmCryptoConfiguration)
|
||||
Timber.d("Realm instance ($sessionRealmCount - $cryptoRealmCount)")
|
||||
|
||||
Timber.d("Cleanup: cancel pending works...")
|
||||
workManagerProvider.cancelAllWorks()
|
||||
|
||||
Timber.d("Cleanup: release session...")
|
||||
sessionManager.releaseSession(sessionId)
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ internal class DefaultSignOutTask @Inject constructor(
|
|||
override suspend fun execute(params: SignOutTask.Params) {
|
||||
// It should be done even after a soft logout, to be sure the deviceId is deleted on the
|
||||
if (params.signOutFromHomeserver) {
|
||||
cleanupSession.stopActiveTasks()
|
||||
Timber.d("SignOut: send request...")
|
||||
try {
|
||||
executeRequest(globalErrorReceiver) {
|
||||
|
@ -67,6 +68,6 @@ internal class DefaultSignOutTask @Inject constructor(
|
|||
.onFailure { Timber.w(it, "Unable to disconnect identity server") }
|
||||
|
||||
Timber.d("SignOut: cleanup session...")
|
||||
cleanupSession.handle()
|
||||
cleanupSession.cleanup()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue