mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 10:25:35 +03:00
separating the user name entered action for login vs register in prep for different behaviours
This commit is contained in:
parent
ffb8b10f66
commit
b8d4ff552f
5 changed files with 19 additions and 9 deletions
|
@ -52,7 +52,10 @@ sealed interface OnboardingAction : VectorViewModelAction {
|
|||
object ResendResetPassword : OnboardingAction
|
||||
object ResetPasswordMailConfirmed : OnboardingAction
|
||||
|
||||
data class MaybeUpdateHomeserverFromMatrixId(val userId: String) : OnboardingAction
|
||||
sealed interface UserNameEnteredAction : OnboardingAction {
|
||||
data class Registration(val userId: String) : UserNameEnteredAction
|
||||
data class Login(val userId: String) : UserNameEnteredAction
|
||||
}
|
||||
sealed interface AuthenticateAction : OnboardingAction {
|
||||
data class Register(val username: String, val password: String, val initialDeviceName: String) : AuthenticateAction
|
||||
data class Login(val username: String, val password: String, val initialDeviceName: String) : AuthenticateAction
|
||||
|
|
|
@ -144,7 +144,7 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
is OnboardingAction.UpdateSignMode -> handleUpdateSignMode(action)
|
||||
is OnboardingAction.InitWith -> handleInitWith(action)
|
||||
is OnboardingAction.HomeServerChange -> withAction(action) { handleHomeserverChange(action) }
|
||||
is OnboardingAction.MaybeUpdateHomeserverFromMatrixId -> handleMaybeUpdateHomeserver(action)
|
||||
is OnboardingAction.UserNameEnteredAction -> handleUserNameEntered(action)
|
||||
is AuthenticateAction -> withAction(action) { handleAuthenticateAction(action) }
|
||||
is OnboardingAction.LoginWithToken -> handleLoginWithToken(action)
|
||||
is OnboardingAction.WebLoginSuccess -> handleWebLoginSuccess(action)
|
||||
|
@ -167,10 +167,17 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun handleMaybeUpdateHomeserver(action: OnboardingAction.MaybeUpdateHomeserverFromMatrixId) {
|
||||
val isFullMatrixId = MatrixPatterns.isUserId(action.userId)
|
||||
private fun handleUserNameEntered(action: OnboardingAction.UserNameEnteredAction) {
|
||||
when(action) {
|
||||
is OnboardingAction.UserNameEnteredAction.Login -> maybeUpdateHomeserver(action.userId)
|
||||
is OnboardingAction.UserNameEnteredAction.Registration -> maybeUpdateHomeserver(action.userId)
|
||||
}
|
||||
}
|
||||
|
||||
private fun maybeUpdateHomeserver(userNameOrMatrixId: String) {
|
||||
val isFullMatrixId = MatrixPatterns.isUserId(userNameOrMatrixId)
|
||||
if (isFullMatrixId) {
|
||||
val domain = action.userId.getServerName().substringBeforeLast(":").ensureProtocol()
|
||||
val domain = userNameOrMatrixId.getServerName().substringBeforeLast(":").ensureProtocol()
|
||||
handleHomeserverChange(OnboardingAction.HomeServerChange.EditHomeServer(domain))
|
||||
} else {
|
||||
// ignore the action
|
||||
|
|
|
@ -60,7 +60,7 @@ class FtueAuthCombinedLoginFragment @Inject constructor(
|
|||
views.loginRoot.realignPercentagesToParent()
|
||||
views.editServerButton.debouncedClicks { viewModel.handle(OnboardingAction.PostViewEvent(OnboardingViewEvents.EditServerSelection)) }
|
||||
views.loginPasswordInput.setOnImeDoneListener { submit() }
|
||||
views.loginInput.setOnFocusLostListener { viewModel.handle(OnboardingAction.MaybeUpdateHomeserverFromMatrixId(views.loginInput.content())) }
|
||||
views.loginInput.setOnFocusLostListener { viewModel.handle(OnboardingAction.UserNameEnteredAction.Login(views.loginInput.content())) }
|
||||
views.loginForgotPassword.debouncedClicks { viewModel.handle(OnboardingAction.PostViewEvent(OnboardingViewEvents.OnForgetPasswordClicked)) }
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ class FtueAuthCombinedRegisterFragment @Inject constructor() : AbstractSSOFtueAu
|
|||
views.editServerButton.debouncedClicks { viewModel.handle(OnboardingAction.PostViewEvent(OnboardingViewEvents.EditServerSelection)) }
|
||||
views.createAccountPasswordInput.setOnImeDoneListener { submit() }
|
||||
views.createAccountInput.setOnFocusLostListener {
|
||||
viewModel.handle(OnboardingAction.MaybeUpdateHomeserverFromMatrixId(views.createAccountInput.content()))
|
||||
viewModel.handle(OnboardingAction.UserNameEnteredAction.Registration(views.createAccountInput.content()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -296,7 +296,7 @@ class OnboardingViewModelTest {
|
|||
val test = viewModel.test()
|
||||
val fullMatrixId = "@a-user:${A_HOMESERVER_URL.removePrefix("https://")}"
|
||||
|
||||
viewModel.handle(OnboardingAction.MaybeUpdateHomeserverFromMatrixId(fullMatrixId))
|
||||
viewModel.handle(OnboardingAction.UserNameEnteredAction.Registration(fullMatrixId))
|
||||
|
||||
test
|
||||
.assertStatesChanges(
|
||||
|
@ -316,7 +316,7 @@ class OnboardingViewModelTest {
|
|||
val test = viewModel.test()
|
||||
val onlyUsername = "a-username"
|
||||
|
||||
viewModel.handle(OnboardingAction.MaybeUpdateHomeserverFromMatrixId(onlyUsername))
|
||||
viewModel.handle(OnboardingAction.UserNameEnteredAction.Registration(onlyUsername))
|
||||
|
||||
test
|
||||
.assertStates(initialState)
|
||||
|
|
Loading…
Reference in a new issue