Login screens: Update the local pendingSessionData synchronously, store asynchronously

This commit is contained in:
Benoit Marty 2019-11-27 16:36:35 +01:00
parent f063abe068
commit bb1c988a49
1 changed files with 17 additions and 12 deletions

View File

@ -72,6 +72,8 @@ internal class DefaultAuthenticationService @Inject constructor(@Unauthenticated
}
override fun getLoginFlow(homeServerConnectionConfig: HomeServerConnectionConfig, callback: MatrixCallback<LoginFlowResult>): Cancelable {
pendingSessionData = null
return GlobalScope.launch(coroutineDispatchers.main) {
pendingSessionStore.delete()
@ -153,17 +155,18 @@ internal class DefaultAuthenticationService @Inject constructor(@Unauthenticated
currentLoginWizard = null
currentRegistrationWizard = null
GlobalScope.launch(coroutineDispatchers.main) {
// Keep only the home sever config
pendingSessionData?.homeServerConnectionConfig
?.let {
pendingSessionData = PendingSessionData(it)
.also { data -> pendingSessionStore.savePendingSessionData(data) }
}
?: run {
// Update the local pendingSessionData synchronously
pendingSessionData = pendingSessionData?.homeServerConnectionConfig
?.let { PendingSessionData(it) }
.also {
GlobalScope.launch(coroutineDispatchers.main) {
if (it == null) {
// Should not happen
pendingSessionData = null
pendingSessionStore.delete()
} else {
pendingSessionStore.savePendingSessionData(it)
}
}
}
}
@ -172,6 +175,8 @@ internal class DefaultAuthenticationService @Inject constructor(@Unauthenticated
currentLoginWizard = null
currentRegistrationWizard = null
pendingSessionData = null
GlobalScope.launch(coroutineDispatchers.main) {
pendingSessionStore.delete()
}