From fd90f3b9fc6e4ca41aae561ad0ba8abd37d0baff Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 27 Nov 2019 15:08:36 +0100 Subject: [PATCH] Login screens: reset SDK when home server url is deleted --- .../matrix/android/api/auth/AuthenticationService.kt | 5 +++++ .../internal/auth/DefaultAuthenticationService.kt | 9 +++++++++ .../im/vector/riotx/features/login/LoginViewModel.kt | 5 +++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/AuthenticationService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/AuthenticationService.kt index 9d4dbd0597..1f3cd3e913 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/AuthenticationService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/AuthenticationService.kt @@ -52,6 +52,11 @@ interface AuthenticationService { */ fun cancelPendingLoginOrRegistration() + /** + * Reset all pending settings, including current HomeServerConnectionConfig + */ + fun reset() + /** * Check if there is an authenticated [Session]. * @return true if there is at least one active session. diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticationService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticationService.kt index 8cdcbe9391..bb447615fc 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticationService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticationService.kt @@ -166,6 +166,15 @@ internal class DefaultAuthenticationService @Inject constructor(@Unauthenticated } } + override fun reset() { + currentLoginWizard = null + currentRegistrationWizard = null + + GlobalScope.launch(coroutineDispatchers.main) { + pendingSessionStore.delete() + } + } + override fun createSessionFromSso(homeServerConnectionConfig: HomeServerConnectionConfig, credentials: Credentials, callback: MatrixCallback): Cancelable { diff --git a/vector/src/main/java/im/vector/riotx/features/login/LoginViewModel.kt b/vector/src/main/java/im/vector/riotx/features/login/LoginViewModel.kt index cff7a1286c..5ec6e98d2f 100644 --- a/vector/src/main/java/im/vector/riotx/features/login/LoginViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/login/LoginViewModel.kt @@ -240,7 +240,8 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi when (action) { LoginAction.ResetLogin -> { - // TODO Clear wizard here? + authenticationService.cancelPendingLoginOrRegistration() + setState { copy( asyncLoginAction = Uninitialized, @@ -249,7 +250,7 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi } } LoginAction.ResetHomeServerUrl -> { - authenticationService.cancelPendingLoginOrRegistration() + authenticationService.reset() setState { copy(