diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/registration/RegistrationWizard.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/registration/RegistrationWizard.kt index 277c0c94dc..9c1e38e31e 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/registration/RegistrationWizard.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/registration/RegistrationWizard.kt @@ -40,4 +40,7 @@ interface RegistrationWizard { fun checkIfEmailHasBeenValidated(delayMillis: Long, callback: MatrixCallback): Cancelable val currentThreePid: String? + + // True when login and password has been sent with success to the homeserver + val isRegistrationStarted: Boolean } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/PendingSessionData.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/PendingSessionData.kt index c230e4198c..0314491d3b 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/PendingSessionData.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/PendingSessionData.kt @@ -45,5 +45,6 @@ internal data class PendingSessionData( * ========================================================================================== */ val currentSession: String? = null, + val isRegistrationStarted: Boolean = false, val currentThreePidData: ThreePidData? = null ) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/PendingSessionEntity.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/PendingSessionEntity.kt index 0440c41f4e..d21c515849 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/PendingSessionEntity.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/PendingSessionEntity.kt @@ -24,5 +24,6 @@ internal open class PendingSessionEntity( var sendAttempt: Int = 0, var resetPasswordDataJson: String? = null, var currentSession: String? = null, + var isRegistrationStarted: Boolean = false, var currentThreePidDataJson: String? = null ) : RealmObject() diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/PendingSessionMapper.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/PendingSessionMapper.kt index 0b2de0ef7f..32e6ba963e 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/PendingSessionMapper.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/PendingSessionMapper.kt @@ -43,6 +43,7 @@ internal class PendingSessionMapper @Inject constructor(moshi: Moshi) { sendAttempt = entity.sendAttempt, resetPasswordData = resetPasswordData, currentSession = entity.currentSession, + isRegistrationStarted = entity.isRegistrationStarted, currentThreePidData = threePidData) } @@ -61,6 +62,7 @@ internal class PendingSessionMapper @Inject constructor(moshi: Moshi) { sendAttempt = sessionData.sendAttempt, resetPasswordDataJson = resetPasswordDataJson, currentSession = sessionData.currentSession, + isRegistrationStarted = sessionData.isRegistrationStarted, currentThreePidDataJson = currentThreePidDataJson ) } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/registration/DefaultRegistrationWizard.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/registration/DefaultRegistrationWizard.kt index 2db1bd94fd..29970b6c0c 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/registration/DefaultRegistrationWizard.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/registration/DefaultRegistrationWizard.kt @@ -67,6 +67,9 @@ internal class DefaultRegistrationWizard( } } + override val isRegistrationStarted: Boolean + get() = pendingSessionData.isRegistrationStarted + override fun getRegistrationFlow(callback: MatrixCallback): Cancelable { val params = RegistrationParams() return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) { @@ -85,6 +88,10 @@ internal class DefaultRegistrationWizard( ) return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) { performRegistrationRequest(params) + .also { + pendingSessionData = pendingSessionData.copy(isRegistrationStarted = true) + .also { pendingSessionStore.savePendingSessionData(it) } + } } } diff --git a/vector/src/main/java/im/vector/riotx/features/login/LoginActivity.kt b/vector/src/main/java/im/vector/riotx/features/login/LoginActivity.kt index c79c86d017..8180fa216f 100644 --- a/vector/src/main/java/im/vector/riotx/features/login/LoginActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/login/LoginActivity.kt @@ -147,8 +147,8 @@ class LoginActivity : VectorBaseActivity(), ToolbarConfigurable { // Display a popup to propose use web fallback onRegistrationStageNotSupported() } else { - // Go on with registration flow - if (loginViewModel.isRegistrationStarted) { + if (loginViewEvents.isRegistrationStarted) { + // Go on with registration flow handleRegistrationNavigation(loginViewEvents.flowResult) } else { // First ask for login and password diff --git a/vector/src/main/java/im/vector/riotx/features/login/LoginViewEvents.kt b/vector/src/main/java/im/vector/riotx/features/login/LoginViewEvents.kt index 252d76f1e4..4c089174f4 100644 --- a/vector/src/main/java/im/vector/riotx/features/login/LoginViewEvents.kt +++ b/vector/src/main/java/im/vector/riotx/features/login/LoginViewEvents.kt @@ -23,7 +23,7 @@ import im.vector.matrix.android.api.auth.registration.FlowResult * Transient events for Login */ sealed class LoginViewEvents { - data class RegistrationFlowResult(val flowResult: FlowResult) : LoginViewEvents() + data class RegistrationFlowResult(val flowResult: FlowResult, val isRegistrationStarted: Boolean) : LoginViewEvents() data class Error(val throwable: Throwable) : LoginViewEvents() object OutdatedHomeserver : LoginViewEvents() } 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 37ab105e40..cff7a1286c 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 @@ -29,7 +29,6 @@ import im.vector.matrix.android.api.auth.registration.RegistrationWizard import im.vector.matrix.android.api.auth.registration.Stage import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.util.Cancelable -import im.vector.matrix.android.api.util.MatrixCallbackDelegate import im.vector.matrix.android.internal.auth.data.LoginFlowTypes import im.vector.riotx.core.di.ActiveSessionHolder import im.vector.riotx.core.extensions.configureAndStart @@ -69,9 +68,9 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi val currentThreePid: String? get() = registrationWizard?.currentThreePid - // True when login and password are sent with success to the homeserver - var isRegistrationStarted: Boolean = false - private set + // True when login and password has been sent with success to the homeserver + val isRegistrationStarted: Boolean + get() = registrationWizard?.isRegistrationStarted == true private val registrationWizard: RegistrationWizard? get() = authenticationService.getRegistrationWizard() @@ -225,14 +224,8 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi action.username, action.password, action.initialDeviceName, - object : MatrixCallbackDelegate(registrationCallback) { - override fun onSuccess(data: RegistrationResult) { - isRegistrationStarted = true - // Not sure that this will work: - // super.onSuccess(data) - registrationCallback.onSuccess(data) - } - }) + registrationCallback + ) } private fun handleCaptchaDone(action: LoginAction.CaptchaDone) { @@ -247,8 +240,7 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi when (action) { LoginAction.ResetLogin -> { - isRegistrationStarted = false - + // TODO Clear wizard here? setState { copy( asyncLoginAction = Uninitialized, @@ -466,7 +458,7 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi handleRegisterDummy() } else { // Notify the user - _viewEvents.post(LoginViewEvents.RegistrationFlowResult(flowResult)) + _viewEvents.post(LoginViewEvents.RegistrationFlowResult(flowResult, isRegistrationStarted)) } }