Login screens: send again 3pid

This commit is contained in:
Benoit Marty 2019-11-21 16:35:13 +01:00
parent 051f77087e
commit 491a38a79f
5 changed files with 58 additions and 8 deletions

View File

@ -33,6 +33,8 @@ interface RegistrationWizard {
fun addThreePid(threePid: RegisterThreePid, callback: MatrixCallback<RegistrationResult>): Cancelable
fun sendAgainThreePid(callback: MatrixCallback<RegistrationResult>): Cancelable
fun handleValidateThreePid(code: String, callback: MatrixCallback<RegistrationResult>): Cancelable
fun checkIfEmailHasBeenValidated(delayMillis: Long, callback: MatrixCallback<RegistrationResult>): Cancelable

View File

@ -122,12 +122,25 @@ internal class DefaultRegistrationWizard(private val homeServerConnectionConfig:
}
override fun addThreePid(threePid: RegisterThreePid, callback: MatrixCallback<RegistrationResult>): Cancelable {
val safeSession = currentSession ?: run {
currentThreePidData = null
return sendThreePid(threePid, callback)
}
override fun sendAgainThreePid(callback: MatrixCallback<RegistrationResult>): Cancelable {
val safeCurrentThreePid = currentThreePidData?.threePid ?: run {
callback.onFailure(IllegalStateException("developer error, call createAccount() method first"))
return NoOpCancellable
}
currentThreePidData = null
return sendThreePid(safeCurrentThreePid, callback)
}
private fun sendThreePid(threePid: RegisterThreePid, callback: MatrixCallback<RegistrationResult>): Cancelable {
val safeSession = currentSession ?: run {
callback.onFailure(IllegalStateException("developer error, call createAccount() method first"))
return NoOpCancellable
}
val job = GlobalScope.launch(coroutineDispatchers.main) {
runCatching {

View File

@ -34,6 +34,7 @@ sealed class LoginAction : VectorViewModelAction {
data class RegisterWith(val username: String, val password: String, val initialDeviceName: String) : RegisterAction()
data class AddThreePid(val threePid: RegisterThreePid) : RegisterAction()
object SendAgainThreePid : RegisterAction()
// TODO Confirm Email (from link in the email, open in the phone, intercepted by RiotX)
data class ValidateThreePid(val code: String) : RegisterAction()

View File

@ -124,7 +124,14 @@ class LoginGenericTextInputFormFragment @Inject constructor(private val errorFor
@OnClick(R.id.loginGenericTextInputFormOtherButton)
fun onOtherButtonClicked() {
// TODO
when (params.mode) {
TextInputFormFragmentMode.ConfirmMsisdn -> {
loginViewModel.handle(LoginAction.SendAgainThreePid)
}
else -> {
// Should not happen, button is not displayed
}
}
}
@OnClick(R.id.loginGenericTextInputFormSubmit)
@ -214,11 +221,15 @@ class LoginGenericTextInputFormFragment @Inject constructor(private val errorFor
}
}
TextInputFormFragmentMode.ConfirmMsisdn -> {
if (throwable is Failure.SuccessError) {
// The entered code is not correct
loginGenericTextInputFormTil.error = getString(R.string.login_validation_code_is_not_correct)
} else {
loginGenericTextInputFormTil.error = errorFormatter.toHumanReadable(throwable)
when {
throwable is Failure.SuccessError ->
// The entered code is not correct
loginGenericTextInputFormTil.error = getString(R.string.login_validation_code_is_not_correct)
throwable.is401() ->
// It can happen if user request again the 3pid
Unit
else ->
loginGenericTextInputFormTil.error = errorFormatter.toHumanReadable(throwable)
}
}
}

View File

@ -111,6 +111,7 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
is LoginAction.AcceptTerms -> handleAcceptTerms()
is LoginAction.RegisterDummy -> handleRegisterDummy()
is LoginAction.AddThreePid -> handleAddThreePid(action)
is LoginAction.SendAgainThreePid -> handleSendAgainThreePid()
is LoginAction.ValidateThreePid -> handleValidateThreePid(action)
is LoginAction.CheckIfEmailHasBeenValidated -> handleCheckIfEmailHasBeenValidated(action)
is LoginAction.StopEmailValidationCheck -> handleStopEmailValidationCheck()
@ -188,6 +189,28 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
})
}
private fun handleSendAgainThreePid() {
setState { copy(asyncRegistration = Loading()) }
currentTask = registrationWizard?.sendAgainThreePid(object : MatrixCallback<RegistrationResult> {
override fun onSuccess(data: RegistrationResult) {
setState {
copy(
asyncRegistration = Uninitialized
)
}
}
override fun onFailure(failure: Throwable) {
_viewEvents.post(LoginViewEvents.RegistrationError(failure))
setState {
copy(
asyncRegistration = Uninitialized
)
}
}
})
}
private fun handleAcceptTerms() {
setState { copy(asyncRegistration = Loading()) }
currentTask = registrationWizard?.acceptTerms(registrationCallback)