mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-22 01:22:46 +02:00
MESSENGER-2762 Initial Merge
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
// $ createRootCoordinator.sh KeyBackupSetup/SecureSetup SecureKeyBackupSetup
|
||||
/*
|
||||
Copyright 2020 New Vector Ltd
|
||||
Copyright (c) 2021 BWI GmbH
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -20,27 +21,34 @@ import UIKit
|
||||
|
||||
@objcMembers
|
||||
final class SecureBackupSetupCoordinator: SecureBackupSetupCoordinatorType {
|
||||
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
|
||||
// MARK: Private
|
||||
|
||||
|
||||
private let navigationRouter: NavigationRouterType
|
||||
private let session: MXSession
|
||||
private let recoveryService: MXRecoveryService
|
||||
private let keyBackup: MXKeyBackup?
|
||||
private let checkKeyBackup: Bool
|
||||
|
||||
private var isBackupSetupMethodKeySupported: Bool {
|
||||
guard let homeserverWellknown = self.session.homeserverWellknown else {
|
||||
return false
|
||||
}
|
||||
return homeserverWellknown.isBackupMethodKeySupported()
|
||||
}
|
||||
private let allowOverwrite: Bool
|
||||
|
||||
// MARK: Public
|
||||
|
||||
// Must be used only internally
|
||||
var childCoordinators: [Coordinator] = []
|
||||
|
||||
|
||||
weak var delegate: SecureBackupSetupCoordinatorDelegate?
|
||||
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
|
||||
/// Initializer
|
||||
/// - Parameters:
|
||||
/// - session: The MXSession.
|
||||
@@ -51,52 +59,65 @@ final class SecureBackupSetupCoordinator: SecureBackupSetupCoordinatorType {
|
||||
self.recoveryService = session.crypto.recoveryService
|
||||
self.keyBackup = session.crypto.backup
|
||||
self.checkKeyBackup = checkKeyBackup
|
||||
|
||||
self.allowOverwrite = allowOverwrite
|
||||
|
||||
|
||||
if let navigationRouter = navigationRouter {
|
||||
self.navigationRouter = navigationRouter
|
||||
} else {
|
||||
self.navigationRouter = NavigationRouter(navigationController: RiotNavigationController())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Public methods
|
||||
|
||||
|
||||
func start() {
|
||||
let rootViewController = self.createIntro()
|
||||
|
||||
|
||||
if self.navigationRouter.modules.isEmpty == false {
|
||||
self.navigationRouter.push(rootViewController, animated: true, popCompletion: nil)
|
||||
} else {
|
||||
self.navigationRouter.setRootModule(rootViewController)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func toPresentable() -> UIViewController {
|
||||
return self.navigationRouter.toPresentable()
|
||||
let controller = self.navigationRouter.toPresentable()
|
||||
|
||||
// If the flow is not cancellable, run it fullscreen
|
||||
if let session = AppDelegate.theDelegate().mxSessions.first as? MXSession {
|
||||
if session.homeserverWellknown.backupRequired() {
|
||||
if #available(iOS 13.0, *) {
|
||||
controller.modalPresentationStyle = .fullScreen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return controller
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Private methods
|
||||
|
||||
private func createIntro() -> SecureBackupSetupIntroViewController {
|
||||
// TODO: Use a coordinator
|
||||
let viewModel = SecureBackupSetupIntroViewModel(keyBackup: self.keyBackup, checkKeyBackup: self.checkKeyBackup)
|
||||
let viewModel = SecureBackupSetupIntroViewModel(keyBackup: self.keyBackup, checkKeyBackup: self.checkKeyBackup, wellKnown: self.session.homeserverWellknown)
|
||||
let introViewController = SecureBackupSetupIntroViewController.instantiate(with: viewModel)
|
||||
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)
|
||||
coordinator.delegate = self
|
||||
coordinator.start()
|
||||
|
||||
|
||||
self.add(childCoordinator: coordinator)
|
||||
self.navigationRouter.push(coordinator, animated: true) { [weak self] in
|
||||
self?.remove(childCoordinator: coordinator)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func showSetupPassphrase() {
|
||||
let coordinator = SecretsSetupRecoveryPassphraseCoordinator(passphraseInput: .new)
|
||||
coordinator.delegate = self
|
||||
@@ -197,15 +218,17 @@ extension SecureBackupSetupCoordinator: SecretsSetupRecoveryKeyCoordinatorDelega
|
||||
|
||||
// MARK: - SecretsSetupRecoveryPassphraseCoordinatorDelegate
|
||||
extension SecureBackupSetupCoordinator: SecretsSetupRecoveryPassphraseCoordinatorDelegate {
|
||||
|
||||
|
||||
func secretsSetupRecoveryPassphraseCoordinator(_ coordinator: SecretsSetupRecoveryPassphraseCoordinatorType, didEnterNewPassphrase passphrase: String) {
|
||||
self.showSetupPassphraseConfirmation(with: passphrase)
|
||||
}
|
||||
|
||||
|
||||
func secretsSetupRecoveryPassphraseCoordinator(_ coordinator: SecretsSetupRecoveryPassphraseCoordinatorType, didConfirmPassphrase passphrase: String) {
|
||||
self.showSetupKey(passphraseOnly: false, passphrase: passphrase)
|
||||
|
||||
// Do not present recovery key export screen if secure backup setup key method is not supported
|
||||
self.showSetupKey(passphraseOnly: !self.isBackupSetupMethodKeySupported, passphrase: passphrase)
|
||||
}
|
||||
|
||||
|
||||
func secretsSetupRecoveryPassphraseCoordinatorDidCancel(_ coordinator: SecretsSetupRecoveryPassphraseCoordinatorType) {
|
||||
self.didCancel()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user