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