Fix multiple server confirmation request crashes and show a modal indicator sooner

This commit is contained in:
Stefan Ceriu
2026-02-09 15:30:09 +02:00
committed by Stefan Ceriu
parent 32ec97a866
commit 20a84dd896
@@ -58,8 +58,12 @@ class ServerConfirmationScreenViewModel: ServerConfirmationScreenViewModelType,
Task { state.window = window } Task { state.window = window }
case .confirm: case .confirm:
switch state.mode { switch state.mode {
case .confirmation: Task { await confirmServer() } case .confirmation:
case .picker: Task { await pickServer() } startLoading()
Task { await confirmServer() }
case .picker:
startLoading()
Task { await pickServer() }
} }
case .changeServer: case .changeServer:
actionsSubject.send(.changeServer) actionsSubject.send(.changeServer)
@@ -69,6 +73,9 @@ class ServerConfirmationScreenViewModel: ServerConfirmationScreenViewModelType,
// MARK: - Private // MARK: - Private
private func confirmServer() async { private func confirmServer() async {
defer { stopLoading() }
startLoading()
let homeserver = authenticationService.homeserver.value let homeserver = authenticationService.homeserver.value
// If the login mode is unknown, the service hasn't been configured and we need to do it now. // If the login mode is unknown, the service hasn't been configured and we need to do it now.
@@ -78,11 +85,6 @@ class ServerConfirmationScreenViewModel: ServerConfirmationScreenViewModelType,
return return
} }
// Note: We don't show the spinner until now as it isn't needed if the service is already
// configured and we're about to use password based login
startLoading()
defer { stopLoading() }
switch await authenticationService.configure(for: homeserver.address, flow: authenticationFlow) { switch await authenticationService.configure(for: homeserver.address, flow: authenticationFlow) {
case .success: case .success:
await fetchLoginURLIfNeededAndContinue() await fetchLoginURLIfNeededAndContinue()
@@ -107,6 +109,9 @@ class ServerConfirmationScreenViewModel: ServerConfirmationScreenViewModelType,
} }
private func pickServer() async { private func pickServer() async {
defer { stopLoading() }
startLoading()
guard let accountProvider = state.bindings.pickerSelection else { guard let accountProvider = state.bindings.pickerSelection else {
fatalError("It shouldn't be possible to confirm without a selection.") fatalError("It shouldn't be possible to confirm without a selection.")
} }
@@ -118,11 +123,6 @@ class ServerConfirmationScreenViewModel: ServerConfirmationScreenViewModelType,
return return
} }
// Note: We don't show the spinner until now as it isn't needed if the service is already
// configured and we're about to use password based login
startLoading()
defer { stopLoading() }
switch await authenticationService.configure(for: accountProvider, flow: authenticationFlow) { switch await authenticationService.configure(for: accountProvider, flow: authenticationFlow) {
case .success: case .success:
await fetchLoginURLIfNeededAndContinue() await fetchLoginURLIfNeededAndContinue()