Login screens: fix several issue with check email screen

This commit is contained in:
Benoit Marty 2019-11-21 15:25:55 +01:00
parent a1f96a5b5a
commit dd44078297
5 changed files with 29 additions and 11 deletions

View file

@ -35,7 +35,7 @@ interface RegistrationWizard {
fun handleValidateThreePid(code: String, callback: MatrixCallback<RegistrationResult>): Cancelable
fun checkIfEmailHasBeenValidated(callback: MatrixCallback<RegistrationResult>): Cancelable
fun checkIfEmailHasBeenValidated(delayMillis: Long, callback: MatrixCallback<RegistrationResult>): Cancelable
val currentThreePid: String?
}

View file

@ -169,14 +169,13 @@ internal class DefaultRegistrationWizard(private val homeServerConnectionConfig:
return CancelableCoroutine(job)
}
override fun checkIfEmailHasBeenValidated(callback: MatrixCallback<RegistrationResult>): Cancelable {
override fun checkIfEmailHasBeenValidated(delayMillis: Long, callback: MatrixCallback<RegistrationResult>): Cancelable {
val safeParam = currentThreePidData?.registrationParams ?: run {
callback.onFailure(IllegalStateException("developer error, no pending three pid"))
return NoOpCancellable
}
// Wait 10 seconds before doing the request
return performRegistrationRequest(safeParam, callback, 10_000)
return performRegistrationRequest(safeParam, callback, delayMillis)
}
override fun handleValidateThreePid(code: String, callback: MatrixCallback<RegistrationResult>): Cancelable {

View file

@ -37,7 +37,8 @@ sealed class LoginAction : VectorViewModelAction {
// TODO Confirm Email (from link in the email, open in the phone, intercepted by RiotX)
data class ValidateThreePid(val code: String) : RegisterAction()
object CheckIfEmailHasBeenValidated : RegisterAction()
data class CheckIfEmailHasBeenValidated(val delayMillis: Long) : RegisterAction()
object StopEmailValidationCheck : RegisterAction()
data class CaptchaDone(val captchaResponse: String) : RegisterAction()
object AcceptTerms : RegisterAction()

View file

@ -40,6 +40,7 @@ import im.vector.riotx.core.utils.PublishDataSource
import im.vector.riotx.features.notifications.PushRuleTriggerListener
import im.vector.riotx.features.session.SessionListener
import timber.log.Timber
import java.util.concurrent.CancellationException
/**
*
@ -111,14 +112,19 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
is LoginAction.RegisterDummy -> handleRegisterDummy()
is LoginAction.AddThreePid -> handleAddThreePid(action)
is LoginAction.ValidateThreePid -> handleValidateThreePid(action)
is LoginAction.CheckIfEmailHasBeenValidated -> handleCheckIfEmailHasBeenValidated()
is LoginAction.CheckIfEmailHasBeenValidated -> handleCheckIfEmailHasBeenValidated(action)
is LoginAction.StopEmailValidationCheck -> handleStopEmailValidationCheck()
}
}
private fun handleCheckIfEmailHasBeenValidated() {
private fun handleCheckIfEmailHasBeenValidated(action: LoginAction.CheckIfEmailHasBeenValidated) {
// We do not want the common progress bar to be displayed, so we do not change asyncRegistration value in the state
currentTask?.cancel()
currentTask = registrationWizard?.checkIfEmailHasBeenValidated(registrationCallback)
currentTask = registrationWizard?.checkIfEmailHasBeenValidated(action.delayMillis, registrationCallback)
}
private fun handleStopEmailValidationCheck() {
currentTask?.cancel()
}
private fun handleValidateThreePid(action: LoginAction.ValidateThreePid) {
@ -149,7 +155,9 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
}
override fun onFailure(failure: Throwable) {
_viewEvents.post(LoginViewEvents.RegistrationError(failure))
if (failure !is CancellationException) {
_viewEvents.post(LoginViewEvents.RegistrationError(failure))
}
setState {
copy(
asyncRegistration = Uninitialized

View file

@ -48,8 +48,18 @@ class LoginWaitForEmailFragment @Inject constructor(private val errorFormatter:
super.onViewCreated(view, savedInstanceState)
setupUi()
}
loginViewModel.handle(LoginAction.CheckIfEmailHasBeenValidated)
override fun onResume() {
super.onResume()
loginViewModel.handle(LoginAction.CheckIfEmailHasBeenValidated(0))
}
override fun onPause() {
super.onPause()
loginViewModel.handle(LoginAction.StopEmailValidationCheck)
}
private fun setupUi() {
@ -59,7 +69,7 @@ class LoginWaitForEmailFragment @Inject constructor(private val errorFormatter:
override fun onRegistrationError(throwable: Throwable) {
if (throwable.is401()) {
// Try again, with a delay
loginViewModel.handle(LoginAction.CheckIfEmailHasBeenValidated)
loginViewModel.handle(LoginAction.CheckIfEmailHasBeenValidated(10_000))
} else {
AlertDialog.Builder(requireActivity())
.setTitle(R.string.dialog_title_error)