Always allow users sign out

- Updates the dialog with a more helpful error message for the user, letting them know what happens if they logout without informing the homeserver.
This commit is contained in:
David Langley 2023-05-23 16:51:26 +01:00
parent df1641995e
commit cee6ec5939
3 changed files with 19 additions and 8 deletions

1
changelog.d/4855.bugfix Normal file
View file

@ -0,0 +1 @@
Fix: Allow users to sign out even if the sign out request fails.

View file

@ -328,6 +328,9 @@
<string name="backup">Back up</string>
<string name="sign_out_bottom_sheet_will_lose_secure_messages">Youll lose access to your encrypted messages unless you back up your keys before signing out.</string>
<string name="sign_out_failed_dialog_message">Cannot reach the homeserver. If you sign out anyway, this device will not be erased from your device list, you may want to remove it using another client.</string>
<string name="sign_out_anyway">Sign out anyway</string>
<!-- splash screen accessibility -->
<string name="loading">Loading…</string>

View file

@ -252,13 +252,10 @@ class MainActivity : VectorBaseActivity<ActivityMainBinding>(), UnlockedActivity
try {
session.signOutService().signOut(!args.isUserLoggedOut)
} catch (failure: Throwable) {
displayError(failure)
displaySignOutFailedDialog(onboardingStore)
return@launch
}
Timber.w("SIGN_OUT: success, start app")
activeSessionHolder.clearActiveSession()
doLocalCleanup(clearPreferences = true, onboardingStore)
startNextActivityAndFinish()
completeSignout(onboardingStore)
}
}
args.clearCache -> {
@ -272,6 +269,15 @@ class MainActivity : VectorBaseActivity<ActivityMainBinding>(), UnlockedActivity
}
}
private fun completeSignout(onboardingStore: VectorSessionStore) {
lifecycleScope.launch {
Timber.w("SIGN_OUT: success, start app")
activeSessionHolder.clearActiveSession()
doLocalCleanup(clearPreferences = true, onboardingStore)
startNextActivityAndFinish()
}
}
override fun handleInvalidToken(globalError: GlobalError.InvalidToken) {
// No op here
Timber.w("Ignoring invalid token global error")
@ -299,12 +305,13 @@ class MainActivity : VectorBaseActivity<ActivityMainBinding>(), UnlockedActivity
}
}
private fun displayError(failure: Throwable) {
private fun displaySignOutFailedDialog(onboardingStore: VectorSessionStore) {
if (lifecycle.currentState.isAtLeast(Lifecycle.State.RESUMED)) {
MaterialAlertDialogBuilder(this)
.setTitle(R.string.dialog_title_error)
.setMessage(errorFormatter.toHumanReadable(failure))
.setPositiveButton(R.string.global_retry) { _, _ -> doCleanUp() }
.setMessage(R.string.sign_out_failed_dialog_message)
.setPositiveButton(R.string.sign_out_anyway) { _, _ -> completeSignout(onboardingStore) }
.setNeutralButton(R.string.global_retry) { _, _ -> doCleanUp() }
.setNegativeButton(R.string.action_cancel) { _, _ -> startNextActivityAndFinish(ignoreClearCredentials = true) }
.setCancelable(false)
.show()