Login screens: save isRegistrationStarted in DB

This commit is contained in:
Benoit Marty 2019-11-27 15:03:10 +01:00
parent 0a19ded167
commit aa51764068
8 changed files with 24 additions and 18 deletions

View File

@ -40,4 +40,7 @@ interface RegistrationWizard {
fun checkIfEmailHasBeenValidated(delayMillis: Long, callback: MatrixCallback<RegistrationResult>): Cancelable
val currentThreePid: String?
// True when login and password has been sent with success to the homeserver
val isRegistrationStarted: Boolean
}

View File

@ -45,5 +45,6 @@ internal data class PendingSessionData(
* ========================================================================================== */
val currentSession: String? = null,
val isRegistrationStarted: Boolean = false,
val currentThreePidData: ThreePidData? = null
)

View File

@ -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()

View File

@ -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
)
}

View File

@ -67,6 +67,9 @@ internal class DefaultRegistrationWizard(
}
}
override val isRegistrationStarted: Boolean
get() = pendingSessionData.isRegistrationStarted
override fun getRegistrationFlow(callback: MatrixCallback<RegistrationResult>): 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) }
}
}
}

View File

@ -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

View File

@ -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()
}

View File

@ -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<RegistrationResult>(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))
}
}