mirror of
https://github.com/element-hq/element-android
synced 2024-11-23 01:45:36 +03:00
Ensure signout service is always use even if users want to ignore sigout error from the server. The SDK is doing more cleanup.
This commit is contained in:
parent
cee6ec5939
commit
997c9dd917
4 changed files with 38 additions and 18 deletions
|
@ -37,6 +37,7 @@ interface SignOutService {
|
|||
/**
|
||||
* Sign out, and release the session, clear all the session data, including crypto data.
|
||||
* @param signOutFromHomeserver true if the sign out request has to be done
|
||||
* @param ignoreServerRequestError true to ignore server error if any
|
||||
*/
|
||||
suspend fun signOut(signOutFromHomeserver: Boolean)
|
||||
suspend fun signOut(signOutFromHomeserver: Boolean, ignoreServerRequestError: Boolean = false)
|
||||
}
|
||||
|
|
|
@ -35,7 +35,12 @@ internal class DefaultSignOutService @Inject constructor(
|
|||
sessionParamsStore.updateCredentials(credentials)
|
||||
}
|
||||
|
||||
override suspend fun signOut(signOutFromHomeserver: Boolean) {
|
||||
return signOutTask.execute(SignOutTask.Params(signOutFromHomeserver))
|
||||
override suspend fun signOut(signOutFromHomeserver: Boolean, ignoreServerRequestError: Boolean) {
|
||||
return signOutTask.execute(
|
||||
SignOutTask.Params(
|
||||
signOutFromHomeserver = signOutFromHomeserver,
|
||||
ignoreServerRequestError = ignoreServerRequestError
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,8 @@ import javax.inject.Inject
|
|||
|
||||
internal interface SignOutTask : Task<SignOutTask.Params, Unit> {
|
||||
data class Params(
|
||||
val signOutFromHomeserver: Boolean
|
||||
val signOutFromHomeserver: Boolean,
|
||||
val ignoreServerRequestError: Boolean,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -59,7 +60,9 @@ internal class DefaultSignOutTask @Inject constructor(
|
|||
// Ignore
|
||||
Timber.w("Ignore error due to https://github.com/matrix-org/synapse/issues/5755")
|
||||
} else {
|
||||
throw throwable
|
||||
if (!params.ignoreServerRequestError) {
|
||||
throw throwable
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ import kotlinx.coroutines.launch
|
|||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import org.matrix.android.sdk.api.failure.GlobalError
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -248,15 +249,7 @@ class MainActivity : VectorBaseActivity<ActivityMainBinding>(), UnlockedActivity
|
|||
}
|
||||
}
|
||||
args.clearCredentials -> {
|
||||
lifecycleScope.launch {
|
||||
try {
|
||||
session.signOutService().signOut(!args.isUserLoggedOut)
|
||||
} catch (failure: Throwable) {
|
||||
displaySignOutFailedDialog(onboardingStore)
|
||||
return@launch
|
||||
}
|
||||
completeSignout(onboardingStore)
|
||||
}
|
||||
signout(session, onboardingStore, ignoreServerError = false)
|
||||
}
|
||||
args.clearCache -> {
|
||||
lifecycleScope.launch {
|
||||
|
@ -269,8 +262,19 @@ class MainActivity : VectorBaseActivity<ActivityMainBinding>(), UnlockedActivity
|
|||
}
|
||||
}
|
||||
|
||||
private fun completeSignout(onboardingStore: VectorSessionStore) {
|
||||
private fun signout(
|
||||
session: Session,
|
||||
onboardingStore: VectorSessionStore,
|
||||
ignoreServerError: Boolean,
|
||||
) {
|
||||
lifecycleScope.launch {
|
||||
try {
|
||||
session.signOutService().signOut(!args.isUserLoggedOut, ignoreServerError)
|
||||
} catch (failure: Throwable) {
|
||||
Timber.e(failure, "SIGN_OUT: error, propose to sign out anyway")
|
||||
displaySignOutFailedDialog(session, onboardingStore)
|
||||
return@launch
|
||||
}
|
||||
Timber.w("SIGN_OUT: success, start app")
|
||||
activeSessionHolder.clearActiveSession()
|
||||
doLocalCleanup(clearPreferences = true, onboardingStore)
|
||||
|
@ -305,13 +309,20 @@ class MainActivity : VectorBaseActivity<ActivityMainBinding>(), UnlockedActivity
|
|||
}
|
||||
}
|
||||
|
||||
private fun displaySignOutFailedDialog(onboardingStore: VectorSessionStore) {
|
||||
private fun displaySignOutFailedDialog(
|
||||
session: Session,
|
||||
onboardingStore: VectorSessionStore,
|
||||
) {
|
||||
if (lifecycle.currentState.isAtLeast(Lifecycle.State.RESUMED)) {
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setTitle(R.string.dialog_title_error)
|
||||
.setMessage(R.string.sign_out_failed_dialog_message)
|
||||
.setPositiveButton(R.string.sign_out_anyway) { _, _ -> completeSignout(onboardingStore) }
|
||||
.setNeutralButton(R.string.global_retry) { _, _ -> doCleanUp() }
|
||||
.setPositiveButton(R.string.sign_out_anyway) { _, _ ->
|
||||
signout(session, onboardingStore, ignoreServerError = true)
|
||||
}
|
||||
.setNeutralButton(R.string.global_retry) { _, _ ->
|
||||
signout(session, onboardingStore, ignoreServerError = false)
|
||||
}
|
||||
.setNegativeButton(R.string.action_cancel) { _, _ -> startNextActivityAndFinish(ignoreClearCredentials = true) }
|
||||
.setCancelable(false)
|
||||
.show()
|
||||
|
|
Loading…
Reference in a new issue