From 82e9a40f301d5bc26a0f5192dfae08421657e7f6 Mon Sep 17 00:00:00 2001 From: Nicolas Buquet Date: Tue, 24 Sep 2024 11:15:57 +0200 Subject: [PATCH] Make `TchapShowVerifyEmailScreen` async to be able to call async `authenticationService.startFlow` --- .../AuthenticationCoordinator.swift | 7 ++- .../Login/AuthenticationLoginModels.swift | 2 +- .../AuthenticationLoginCoordinator.swift | 59 ++++++++++--------- 3 files changed, 38 insertions(+), 30 deletions(-) diff --git a/Riot/Modules/Authentication/AuthenticationCoordinator.swift b/Riot/Modules/Authentication/AuthenticationCoordinator.swift index 6f51c8cdd..09277ab3f 100644 --- a/Riot/Modules/Authentication/AuthenticationCoordinator.swift +++ b/Riot/Modules/Authentication/AuthenticationCoordinator.swift @@ -174,7 +174,7 @@ final class AuthenticationCoordinator: NSObject, AuthenticationCoordinatorProtoc } else { // Tchap: force email registration mode // showRegistrationScreen() - TchapShowVerifyEmailScreen() + await TchapShowVerifyEmailScreen() } case .login: if authenticationService.state.homeserver.needsLoginFallback { @@ -410,9 +410,12 @@ final class AuthenticationCoordinator: NSObject, AuthenticationCoordinatorProtoc // Tchap: start Registration with VerifyEmail screen /// Shows the login screen. - @MainActor private func TchapShowVerifyEmailScreen() { + @MainActor private func TchapShowVerifyEmailScreen() async { MXLog.debug("[AuthenticationCoordinator] TchapShowVerifyEmailScreen") + // Call `startFlow` here to get `registrationWizard` initialized. + try? await authenticationService.startFlow(.register) + guard let registrationWizard = authenticationService.registrationWizard else { MXLog.failure("[AuthenticationCoordinator] showStage: Missing the RegistrationWizard needed to complete the stage.") displayError(message: VectorL10n.errorCommonMessage) diff --git a/RiotSwiftUI/Modules/Authentication/Login/AuthenticationLoginModels.swift b/RiotSwiftUI/Modules/Authentication/Login/AuthenticationLoginModels.swift index 06d4ef16d..aedc32535 100644 --- a/RiotSwiftUI/Modules/Authentication/Login/AuthenticationLoginModels.swift +++ b/RiotSwiftUI/Modules/Authentication/Login/AuthenticationLoginModels.swift @@ -95,7 +95,7 @@ struct AuthenticationLoginViewState: BindableState { switch tchapAuthenticationMode { case .password: return !isLoading && tchapEmailIsValid - case .sso(let ssoIdentityProviders): + case .sso: return !isLoading && tchapEmailIsValid default: return hasValidCredentials && !isLoading diff --git a/RiotSwiftUI/Modules/Authentication/Login/Coordinator/AuthenticationLoginCoordinator.swift b/RiotSwiftUI/Modules/Authentication/Login/Coordinator/AuthenticationLoginCoordinator.swift index 40d0e0e6e..b1d077841 100644 --- a/RiotSwiftUI/Modules/Authentication/Login/Coordinator/AuthenticationLoginCoordinator.swift +++ b/RiotSwiftUI/Modules/Authentication/Login/Coordinator/AuthenticationLoginCoordinator.swift @@ -290,35 +290,40 @@ final class AuthenticationLoginCoordinator: Coordinator, Presentable { @MainActor private func showForgotPasswordScreen() { MXLog.debug("[AuthenticationLoginCoordinator] showForgotPasswordScreen") - guard let loginWizard = loginWizard else { - MXLog.failure("[AuthenticationLoginCoordinator] The login wizard was requested before getting the login flow.") - return - } - - let modalRouter = NavigationRouter() - - let parameters = AuthenticationForgotPasswordCoordinatorParameters(navigationRouter: modalRouter, - loginWizard: loginWizard, - homeserver: parameters.authenticationService.state.homeserver) - let coordinator = AuthenticationForgotPasswordCoordinator(parameters: parameters) - coordinator.callback = { [weak self, weak coordinator] result in - guard let self = self, let coordinator = coordinator else { return } - switch result { - case .success: - self.navigationRouter.dismissModule(animated: true, completion: nil) - self.successIndicator = self.indicatorPresenter.present(.success(label: VectorL10n.done)) - case .cancel: - self.navigationRouter.dismissModule(animated: true, completion: nil) + // Tchap: Call `startFlow` here to get `loginWizard` initialized. + Task { + try? await authenticationService.startFlow(.login) + + guard let loginWizard = loginWizard else { + MXLog.failure("[AuthenticationLoginCoordinator] The login wizard was requested before getting the login flow.") + return } - self.remove(childCoordinator: coordinator) + + let modalRouter = NavigationRouter() + + let parameters = AuthenticationForgotPasswordCoordinatorParameters(navigationRouter: modalRouter, + loginWizard: loginWizard, + homeserver: parameters.authenticationService.state.homeserver) + let coordinator = AuthenticationForgotPasswordCoordinator(parameters: parameters) + coordinator.callback = { [weak self, weak coordinator] result in + guard let self = self, let coordinator = coordinator else { return } + switch result { + case .success: + self.navigationRouter.dismissModule(animated: true, completion: nil) + self.successIndicator = self.indicatorPresenter.present(.success(label: VectorL10n.done)) + case .cancel: + self.navigationRouter.dismissModule(animated: true, completion: nil) + } + self.remove(childCoordinator: coordinator) + } + + coordinator.start() + add(childCoordinator: coordinator) + + modalRouter.setRootModule(coordinator) + + navigationRouter.present(modalRouter, animated: true) } - - coordinator.start() - add(childCoordinator: coordinator) - - modalRouter.setRootModule(coordinator) - - navigationRouter.present(modalRouter, animated: true) } /// Shows the QR login screen.