Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Secrets recovery: Fix an issue where the Secrets Reset screen would open twice. #7404

Merged
merged 2 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Riot/Modules/Secrets/Recover/SecretsRecoveryCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,12 @@ final class SecretsRecoveryCoordinator: SecretsRecoveryCoordinatorType {
private func showSecureBackupSetup(checkKeyBackup: Bool) {
let coordinator = SecureBackupSetupCoordinator(session: self.session, checkKeyBackup: checkKeyBackup, navigationRouter: self.navigationRouter, cancellable: self.cancellable)
coordinator.delegate = self
coordinator.start()

self.navigationRouter.push(coordinator.toPresentable(), animated: true, popCompletion: { [weak self] in
// Fix: calling coordinator.start() will update the navigationRouter without a popCompletion
coordinator.start(popCompletion: { [weak self] in
self?.remove(childCoordinator: coordinator)
})
// Fix: do not push the presentable from the coordinator to the navigation router as this has already been done by coordinator.start().
// Also, coordinator.toPresentable() returns a navigation controller, which cannot be pushed into a navigation router.
self.add(childCoordinator: coordinator)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Riot/Modules/Secrets/Reset/SecretsResetCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ extension SecretsResetCoordinator: SecretsResetViewModelCoordinatorDelegate {
extension SecretsResetCoordinator: ReauthenticationCoordinatorDelegate {

func reauthenticationCoordinatorDidComplete(_ coordinator: ReauthenticationCoordinatorType, withAuthenticationParameters authenticationParameters: [String: Any]?) {

self.secretsResetViewModel.process(viewAction: .authenticationInfoEntered(authenticationParameters ?? [:]))
}

func reauthenticationCoordinatorDidCancel(_ coordinator: ReauthenticationCoordinatorType) {
self.secretsResetViewModel.process(viewAction: .authenticationCancelled)
self.remove(childCoordinator: coordinator)
}

Expand Down
1 change: 1 addition & 0 deletions Riot/Modules/Secrets/Reset/SecretsResetViewAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Foundation
enum SecretsResetViewAction {
case loadData
case reset
case authenticationCancelled
case authenticationInfoEntered(_ authInfo: [String: Any])
case cancel
}
6 changes: 6 additions & 0 deletions Riot/Modules/Secrets/Reset/SecretsResetViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ final class SecretsResetViewController: UIViewController {
self.renderLoading()
case .resetDone:
self.renderLoaded()
case .resetCancelled:
self.renderCancelled()
case .error(let error):
self.render(error: error)
}
Expand All @@ -145,6 +147,10 @@ final class SecretsResetViewController: UIViewController {
self.activityPresenter.removeCurrentActivityIndicator(animated: true)
}

private func renderCancelled() {
self.activityPresenter.removeCurrentActivityIndicator(animated: true)
}

private func render(error: Error) {
self.activityPresenter.removeCurrentActivityIndicator(animated: true)
self.errorPresenter.presentError(from: self, forError: error, animated: true, handler: nil)
Expand Down
9 changes: 8 additions & 1 deletion Riot/Modules/Secrets/Reset/SecretsResetViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ final class SecretsResetViewModel: SecretsResetViewModelType {
break
case .reset:
self.askAuthentication()
case .authenticationCancelled:
self.authenticationCancelled()
case .authenticationInfoEntered(let authParameters):
self.resetSecrets(with: authParameters)
case .cancel:
Expand All @@ -68,7 +70,6 @@ final class SecretsResetViewModel: SecretsResetViewModelType {
}
MXLog.debug("[SecretsResetViewModel] resetSecrets")

self.update(viewState: .resetting)
crossSigning.setup(withAuthParams: authParameters, success: { [weak self] in
guard let self = self else {
return
Expand Down Expand Up @@ -96,7 +97,13 @@ final class SecretsResetViewModel: SecretsResetViewModelType {
}

private func askAuthentication() {
self.update(viewState: .resetting)

let setupCrossSigningRequest = self.crossSigningService.setupCrossSigningRequest()
self.coordinatorDelegate?.secretsResetViewModel(self, needsToAuthenticateWith: setupCrossSigningRequest)
}

private func authenticationCancelled() {
self.update(viewState: .resetCancelled)
}
}
1 change: 1 addition & 0 deletions Riot/Modules/Secrets/Reset/SecretsResetViewState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ import Foundation
enum SecretsResetViewState {
case resetting
case resetDone
case resetCancelled
case error(Error)
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,19 @@ final class SecureBackupSetupCoordinator: SecureBackupSetupCoordinatorType {
// MARK: - Public methods

func start() {
start(popCompletion: nil)
}

func start(popCompletion: (() -> Void)?) {
let rootViewController = self.createIntro()

if self.navigationRouter.modules.isEmpty == false {
self.navigationRouter.push(rootViewController, animated: true, popCompletion: nil)
self.navigationRouter.push(rootViewController, animated: true, popCompletion: popCompletion)
} else {
self.navigationRouter.setRootModule(rootViewController)
self.navigationRouter.setRootModule(rootViewController, popCompletion: popCompletion)
}
}

func toPresentable() -> UIViewController {
return self.navigationRouter
.toPresentable()
Expand Down
1 change: 1 addition & 0 deletions changelog.d/pr-7404.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix an issue where the Secrets Reset screen would open twice.