Skip to content

Commit

Permalink
Fix: don’t allow to reset secrets if it is already in progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
nimau committed May 2, 2023
1 parent 5cf28f4 commit 0240e35
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 2 deletions.
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)
}
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.

0 comments on commit 0240e35

Please sign in to comment.