updating the server selection on non Edit/Select events

- such as deeplinks
- extracts a common function
This commit is contained in:
Adam Brown 2022-04-14 11:46:34 +01:00
parent ee693b5ad4
commit a34b424b7b
1 changed files with 17 additions and 17 deletions

View File

@ -625,32 +625,20 @@ class OnboardingViewModel @AssistedInject constructor(
_viewEvents.post(OnboardingViewEvents.OutdatedHomeserver)
}
val state = awaitState()
when (trigger) {
is OnboardingAction.HomeServerChange.EditHomeServer -> {
when (state.onboardingFlow) {
when (awaitState().onboardingFlow) {
OnboardingFlow.SignUp -> internalRegisterAction(RegisterAction.StartRegistration) { _ ->
setState {
copy(
serverType = alignServerTypeAfterSubmission(config, serverTypeOverride),
selectedHomeserver = authResult.selectedHomeserver,
)
}
updateServerSelection(config, serverTypeOverride, authResult)
_viewEvents.post(OnboardingViewEvents.OnHomeserverEdited)
}
else -> throw IllegalArgumentException("developer error")
}
}
is OnboardingAction.HomeServerChange.SelectHomeServer -> {
setState {
copy(
serverType = alignServerTypeAfterSubmission(config, serverTypeOverride),
selectedHomeserver = authResult.selectedHomeserver,
)
}
updateServerSelection(config, serverTypeOverride, authResult)
if (authResult.selectedHomeserver.preferredLoginMode.supportsSignModeScreen()) {
when (state.onboardingFlow) {
when (awaitState().onboardingFlow) {
OnboardingFlow.SignIn -> internalRegisterAction(RegisterAction.StartRegistration, ::emitFlowResultViewEvent)
OnboardingFlow.SignUp -> internalRegisterAction(RegisterAction.StartRegistration, ::emitFlowResultViewEvent)
OnboardingFlow.SignInSignUp,
@ -662,7 +650,19 @@ class OnboardingViewModel @AssistedInject constructor(
_viewEvents.post(OnboardingViewEvents.OnLoginFlowRetrieved)
}
}
else -> _viewEvents.post(OnboardingViewEvents.OnLoginFlowRetrieved)
else -> {
updateServerSelection(config, serverTypeOverride, authResult)
_viewEvents.post(OnboardingViewEvents.OnLoginFlowRetrieved)
}
}
}
private fun updateServerSelection(config: HomeServerConnectionConfig, serverTypeOverride: ServerType?, authResult: StartAuthenticationFlowUseCase.StartAuthenticationResult) {
setState {
copy(
serverType = alignServerTypeAfterSubmission(config, serverTypeOverride),
selectedHomeserver = authResult.selectedHomeserver,
)
}
}