Add cancellable property to secureBackup/recovery coordinators

This commit is contained in:
Arnaud Ringenbach
2022-03-09 10:41:48 +01:00
parent e79e77e1f0
commit 010e5d8d9f
21 changed files with 93 additions and 43 deletions
@@ -51,7 +51,7 @@ final class SecureBackupSetupIntroViewController: UIViewController {
// MARK: - Setup
class func instantiate(with viewModel: SecureBackupSetupIntroViewModelType, cancellable: Bool = true) -> SecureBackupSetupIntroViewController {
class func instantiate(with viewModel: SecureBackupSetupIntroViewModelType, cancellable: Bool) -> SecureBackupSetupIntroViewController {
let viewController = StoryboardScene.SecureBackupSetupIntroViewController.initialScene.instantiate()
viewController.viewModel = viewModel
viewController.cancellable = cancellable
@@ -31,6 +31,7 @@ final class SecureBackupSetupCoordinator: SecureBackupSetupCoordinatorType {
private let keyBackup: MXKeyBackup?
private let checkKeyBackup: Bool
private let allowOverwrite: Bool
private let cancellable: Bool
// MARK: Public
@@ -46,12 +47,14 @@ final class SecureBackupSetupCoordinator: SecureBackupSetupCoordinatorType {
/// - session: The MXSession.
/// - checkKeyBackup: Indicate false to ignore existing key backup.
/// - navigationRouter: Use existing navigation router to plug this flow or let nil to use new one.
init(session: MXSession, checkKeyBackup: Bool = true, allowOverwrite: Bool = false, navigationRouter: NavigationRouterType? = nil) {
/// - cancellable: Whether secure backup can be cancelled
init(session: MXSession, checkKeyBackup: Bool = true, allowOverwrite: Bool = false, navigationRouter: NavigationRouterType? = nil, cancellable: Bool) {
self.session = session
self.recoveryService = session.crypto.recoveryService
self.keyBackup = session.crypto.backup
self.checkKeyBackup = checkKeyBackup
self.allowOverwrite = allowOverwrite
self.cancellable = cancellable
if let navigationRouter = navigationRouter {
self.navigationRouter = navigationRouter
@@ -73,7 +76,9 @@ final class SecureBackupSetupCoordinator: SecureBackupSetupCoordinatorType {
}
func toPresentable() -> UIViewController {
return self.navigationRouter.toPresentable()
return self.navigationRouter
.toPresentable()
.vc_setModalFullScreen(!self.cancellable)
}
// MARK: - Private methods
@@ -81,13 +86,13 @@ final class SecureBackupSetupCoordinator: SecureBackupSetupCoordinatorType {
private func createIntro() -> SecureBackupSetupIntroViewController {
// TODO: Use a coordinator
let viewModel = SecureBackupSetupIntroViewModel(keyBackup: self.keyBackup, checkKeyBackup: self.checkKeyBackup)
let introViewController = SecureBackupSetupIntroViewController.instantiate(with: viewModel)
let introViewController = SecureBackupSetupIntroViewController.instantiate(with: viewModel, cancellable: self.cancellable)
introViewController.delegate = self
return introViewController
}
private func showSetupKey(passphraseOnly: Bool, passphrase: String? = nil) {
let coordinator = SecretsSetupRecoveryKeyCoordinator(recoveryService: self.recoveryService, passphrase: passphrase, passphraseOnly: passphraseOnly, allowOverwrite: allowOverwrite)
let coordinator = SecretsSetupRecoveryKeyCoordinator(recoveryService: self.recoveryService, passphrase: passphrase, passphraseOnly: passphraseOnly, allowOverwrite: allowOverwrite, cancellable: self.cancellable)
coordinator.delegate = self
coordinator.start()
@@ -98,7 +103,7 @@ final class SecureBackupSetupCoordinator: SecureBackupSetupCoordinatorType {
}
private func showSetupPassphrase() {
let coordinator = SecretsSetupRecoveryPassphraseCoordinator(passphraseInput: .new)
let coordinator = SecretsSetupRecoveryPassphraseCoordinator(passphraseInput: .new, cancellable: self.cancellable)
coordinator.delegate = self
coordinator.start()
@@ -109,7 +114,7 @@ final class SecureBackupSetupCoordinator: SecureBackupSetupCoordinatorType {
}
private func showSetupPassphraseConfirmation(with passphrase: String) {
let coordinator = SecretsSetupRecoveryPassphraseCoordinator(passphraseInput: .confirm(passphrase))
let coordinator = SecretsSetupRecoveryPassphraseCoordinator(passphraseInput: .confirm(passphrase), cancellable: self.cancellable)
coordinator.delegate = self
coordinator.start()
@@ -54,9 +54,13 @@ final class SecureBackupSetupCoordinatorBridgePresenter: NSObject {
// func present(from viewController: UIViewController, animated: Bool) {
// self.present(from: viewController, animated: animated)
// }
func present(from viewController: UIViewController, animated: Bool) {
let secureBackupSetupCoordinator = SecureBackupSetupCoordinator(session: self.session, allowOverwrite: self.allowOverwrite)
self.present(from: viewController, animated: animated, cancellable: true)
}
func present(from viewController: UIViewController, animated: Bool, cancellable: Bool) {
let secureBackupSetupCoordinator = SecureBackupSetupCoordinator(session: self.session, allowOverwrite: self.allowOverwrite, cancellable: cancellable)
secureBackupSetupCoordinator.delegate = self
viewController.present(secureBackupSetupCoordinator.toPresentable(), animated: animated, completion: nil)
secureBackupSetupCoordinator.start()