Skip to content

Commit

Permalink
Make TchapShowVerifyEmailScreen async to be able to call async `aut…
Browse files Browse the repository at this point in the history
…henticationService.startFlow`
  • Loading branch information
NicolasBuquet committed Sep 24, 2024
1 parent b924986 commit 82e9a40
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 30 deletions.
7 changes: 5 additions & 2 deletions Riot/Modules/Authentication/AuthenticationCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 82e9a40

Please sign in to comment.