Files
bundesmessenger-ios/Riot/Modules/SecureBackup/Setup/Intro/SecureBackupSetupIntroViewController.swift
T
JanNiklas Grabowski b298dedc22 chore: update from foss 1.11.19 (MESSENGER-6656)
Merge commit 'f823ab9aae70e8d15ed7cc079210dd9bbbb6c8e1' into feature/foss_update_1_11_19

* commit 'f823ab9aae70e8d15ed7cc079210dd9bbbb6c8e1':
  finish version++
  version++
  comments
  update submodule
  remove obsolete tests
  removed unused code
  update submodule
  fix
  Libolm removal
  update license macro
  update license
  Prepare for new sprint

# Conflicts:
#	Config/AppVersion.xcconfig
#	IDETemplateMacros.plist
#	LICENSE
#	README.md
#	Riot/Categories/MXSession+Riot.m
#	Riot/Managers/EncryptionKeyManager/EncryptionKeyManager.swift
#	Riot/Managers/KeyValueStorage/Extensions/Keychain.swift
#	Riot/Managers/KeyValueStorage/KeyValueStore.swift
#	Riot/Managers/KeyValueStorage/KeychainStore.swift
#	Riot/Managers/KeyValueStorage/MemoryStore.swift
#	Riot/Managers/PushNotification/PushNotificationService.m
#	Riot/Managers/Settings/RiotSettings.swift
#	Riot/Managers/Settings/Shared/RiotSharedSettings.swift
#	Riot/Modules/Analytics/AnalyticsUIElement.swift
#	Riot/Modules/Application/AppCoordinator.swift
#	Riot/Modules/Application/LegacyAppDelegate.h
#	Riot/Modules/Application/LegacyAppDelegate.m
#	Riot/Modules/Authentication/Legacy/AuthenticationViewController.h
#	Riot/Modules/Authentication/Legacy/AuthenticationViewController.m
#	Riot/Modules/Authentication/Legacy/Views/AuthInputsView.h
#	Riot/Modules/Authentication/Legacy/Views/AuthInputsView.m
#	Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m
#	Riot/Modules/Common/Recents/RecentsViewController.m
#	Riot/Modules/Common/WebViewController/WebViewViewController.m
#	Riot/Modules/Contacts/Details/ContactDetailsViewController.m
#	Riot/Modules/Contacts/Views/ContactTableViewCell.m
#	Riot/Modules/Favorites/FavouritesViewController.h
#	Riot/Modules/Favorites/FavouritesViewController.m
#	Riot/Modules/GlobalSearch/UnifiedSearchViewController.m
#	Riot/Modules/People/PeopleViewController.h
#	Riot/Modules/People/PeopleViewController.m
#	Riot/Modules/Room/ContextualMenu/ReactionsMenu/ReactionsMenuViewModel.swift
#	Riot/Modules/Room/DataSources/RoomDataSource.m
#	Riot/Modules/Room/Files/RoomFilesViewController.m
#	Riot/Modules/Room/Members/Detail/RoomMemberDetailsViewController.m
#	Riot/Modules/Room/Members/RoomParticipantsViewController.m
#	Riot/Modules/Room/RoomViewController.m
#	Riot/Modules/Room/Settings/RoomSettingsViewController.m
#	Riot/Modules/Room/TimelineCells/RoomCreationIntro/RoomCreationIntroCell.swift
#	Riot/Modules/Room/TimelineCells/RoomCreationIntro/RoomCreationIntroCellContentView.swift
#	Riot/Modules/Room/TimelineCells/RoomCreationIntro/RoomCreationIntroViewData.swift
#	Riot/Modules/Room/TimelineCells/RoomTimelineCellIdentifier.h
#	Riot/Modules/Rooms/RoomsViewController.h
#	Riot/Modules/Rooms/ShowDirectory/Cells/Network/DirectoryNetworkTableHeaderFooterView.swift
#	Riot/Modules/Rooms/ShowDirectory/Cells/Room/DirectoryRoomTableViewCell.swift
#	Riot/Modules/Rooms/ShowDirectory/PublicRoomsDirectoryViewModel.swift
#	Riot/Modules/Secrets/Recover/RecoverWithKey/SecretsRecoveryWithKeyCoordinator.swift
#	Riot/Modules/Secrets/Recover/RecoverWithKey/SecretsRecoveryWithKeyViewController.swift
#	Riot/Modules/Secrets/Recover/RecoverWithPassphrase/SecretsRecoveryWithPassphraseCoordinator.swift
#	Riot/Modules/Secrets/Recover/RecoverWithPassphrase/SecretsRecoveryWithPassphraseViewController.swift
#	Riot/Modules/Secrets/Recover/SecretsRecoveryCoordinator.swift
#	Riot/Modules/SecureBackup/Setup/Intro/SecureBackupSetupIntroViewController.swift
#	Riot/Modules/SecureBackup/Setup/Intro/SecureBackupSetupIntroViewModel.swift
#	Riot/Modules/SecureBackup/Setup/Intro/SecureBackupSetupIntroViewModelType.swift
#	Riot/Modules/SetPinCode/PinCodePreferences.swift
#	Riot/Modules/SetPinCode/SetupBiometrics/BiometricsAuthenticationPresenter.swift
#	Riot/Modules/Settings/Security/ManageSession/ManageSessionViewController.m
#	Riot/Modules/Settings/Security/SecurityViewController.m
#	Riot/Modules/Settings/SettingsViewController.m
#	Riot/Modules/SplitView/SplitViewCoordinator.swift
#	Riot/Modules/SplitView/SplitViewCoordinatorType.swift
#	Riot/Modules/StartChat/StartChatViewController.m
#	Riot/Modules/TabBar/MasterTabBarController.h
#	Riot/Modules/TabBar/MasterTabBarController.m
#	Riot/Utils/EventFormatter.m
#	Riot/Utils/HTMLFormatter.swift
#	Riot/Utils/Tools.m
#	RiotNSE/NotificationService.swift
2024-10-18 15:45:54 +02:00

248 lines
9.8 KiB
Swift

/*
Copyright 2020-2024 New Vector Ltd.
Copyright (c) 2021 BWI GmbH
SPDX-License-Identifier: AGPL-3.0-only
Please see LICENSE in the repository root for full details.
*/
import UIKit
protocol SecureBackupSetupIntroViewControllerDelegate: AnyObject {
func secureBackupSetupIntroViewControllerDidTapUseKey(_ secureBackupSetupIntroViewController: SecureBackupSetupIntroViewController)
func secureBackupSetupIntroViewControllerDidTapUsePassphrase(_ secureBackupSetupIntroViewController: SecureBackupSetupIntroViewController)
func secureBackupSetupIntroViewControllerDidCancel(_ secureBackupSetupIntroViewController: SecureBackupSetupIntroViewController, showSkipAlert: Bool)
func secureBackupSetupIntroViewControllerDidTapConnectToKeyBackup(_ secureBackupSetupIntroViewController: SecureBackupSetupIntroViewController)
}
@objcMembers
final class SecureBackupSetupIntroViewController: UIViewController {
// MARK: - Properties
// MARK: Outlets
@IBOutlet private weak var informationLabel: UILabel!
@IBOutlet private weak var topSeparatorView: UIView!
@IBOutlet private weak var secureKeyCell: SecureBackupSetupIntroCell!
@IBOutlet private weak var securePassphraseCell: SecureBackupSetupIntroCell!
// MARK: Private
private var viewModel: SecureBackupSetupIntroViewModelType!
private var cancellable: Bool!
private var theme: Theme!
private var activityIndicatorPresenter: ActivityIndicatorPresenter!
private var errorPresenter: MXKErrorPresentation!
// MARK: Public
weak var delegate: SecureBackupSetupIntroViewControllerDelegate?
// MARK: - Setup
class func instantiate(with viewModel: SecureBackupSetupIntroViewModelType, cancellable: Bool) -> SecureBackupSetupIntroViewController {
let viewController = StoryboardScene.SecureBackupSetupIntroViewController.initialScene.instantiate()
viewController.viewModel = viewModel
viewController.cancellable = cancellable
viewController.theme = ThemeService.shared().theme
return viewController
}
// MARK: - Life cycle
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.vc_removeBackTitle()
self.setupViews()
self.activityIndicatorPresenter = ActivityIndicatorPresenter()
self.errorPresenter = MXKErrorAlertPresentation()
self.registerThemeServiceDidChangeThemeNotification()
self.update(theme: self.theme)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self.checkKeyBackup()
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return self.theme.statusBarStyle
}
// MARK: - Private
private func setupViews() {
if self.cancellable {
let cancelBarButtonItem = MXKBarButtonItem(title: VectorL10n.cancel, style: .plain) { [weak self] in
guard let self = self else {
return
}
self.delegate?.secureBackupSetupIntroViewControllerDidCancel(self, showSkipAlert: true)
}
self.navigationItem.rightBarButtonItem = cancelBarButtonItem
}
self.title = BWIL10n.secureKeyBackupSetupIntroTitle
self.informationLabel.text = BWIL10n.secureKeyBackupSetupIntroInfo
self.secureKeyCell.fill(title: VectorL10n.secureKeyBackupSetupIntroUseSecurityKeyTitle,
information: VectorL10n.secureKeyBackupSetupIntroUseSecurityKeyInfo,
image: Asset.Images.secretsSetupKey.image)
self.secureKeyCell.action = { [weak self] in
guard let self = self else {
return
}
self.delegate?.secureBackupSetupIntroViewControllerDidTapUseKey(self)
}
self.securePassphraseCell.fill(title: BWIL10n.secureKeyBackupSetupIntroUseSecurityPassphraseTitle,
information: BWIL10n.secureKeyBackupSetupIntroUseSecurityPassphraseInfo,
image: Asset.Images.secretsSetupPassphrase.image)
self.securePassphraseCell.action = { [weak self] in
guard let self = self else {
return
}
self.delegate?.secureBackupSetupIntroViewControllerDidTapUsePassphrase(self)
}
setupBackupMethods()
}
private func setupBackupMethods() {
let secureBackupSetupMethods = self.viewModel.homeserverEncryptionConfiguration.secureBackupSetupMethods
// Hide setup methods that are not listed
if !secureBackupSetupMethods.contains(.key) {
self.secureKeyCell.isHidden = true
}
if !secureBackupSetupMethods.contains(.passphrase) {
self.securePassphraseCell.isHidden = true
}
}
private func renderLoading() {
self.activityIndicatorPresenter.presentActivityIndicator(on: self.view, animated: true)
}
private func renderLoaded() {
self.activityIndicatorPresenter.removeCurrentActivityIndicator(animated: true)
}
private func render(error: Error) {
self.activityIndicatorPresenter.removeCurrentActivityIndicator(animated: true)
self.errorPresenter.presentError(from: self, forError: error, animated: true, handler: nil)
}
private func update(theme: Theme) {
self.theme = theme
self.view.backgroundColor = theme.headerBackgroundColor
if let navigationBar = self.navigationController?.navigationBar {
theme.applyStyle(onNavigationBar: navigationBar)
}
self.informationLabel.textColor = theme.textPrimaryColor
self.topSeparatorView.backgroundColor = theme.lineBreakColor
self.secureKeyCell.update(theme: theme)
self.securePassphraseCell.update(theme: theme)
}
private func registerThemeServiceDidChangeThemeNotification() {
NotificationCenter.default.addObserver(self, selector: #selector(themeDidChange), name: .themeServiceDidChangeTheme, object: nil)
}
@objc private func themeDidChange() {
self.update(theme: ThemeService.shared().theme)
}
// TODO: To remove
private func checkKeyBackup() {
guard self.viewModel.checkKeyBackup else {
return
}
guard let keyBackup = self.viewModel.keyBackup else {
return
}
// If a backup already exists and we do not have the private key,
// we need to get this private key first. Ask the user to make a key backup restore to catch it
if keyBackup.keyBackupVersion != nil && keyBackup.hasPrivateKeyInCryptoStore == false {
// don't show dialog if forced, already asked before in mandatory verification recover
if BWIBuildSettings.shared.forceResetBackupIfLost {
let alertController = UIAlertController(title: VectorL10n.secureKeyBackupSetupExistingBackupErrorTitle,
message: VectorL10n.secureKeyBackupSetupExistingBackupErrorInfo,
preferredStyle: .alert)
let connectAction = UIAlertAction(title: VectorL10n.secureKeyBackupSetupExistingBackupErrorUnlockIt, style: .default) { (_) in
self.delegate?.secureBackupSetupIntroViewControllerDidTapConnectToKeyBackup(self)
}
let resetAction = UIAlertAction(title: VectorL10n.secureKeyBackupSetupExistingBackupErrorDeleteIt, style: .destructive) { (_) in
self.deleteKeybackup()
}
} else {
let alertContoller = UIAlertController(title: VectorL10n.secureKeyBackupSetupExistingBackupErrorTitle,
message: VectorL10n.secureKeyBackupSetupExistingBackupErrorInfo,
preferredStyle: .alert)
let connectAction = UIAlertAction(title: VectorL10n.secureKeyBackupSetupExistingBackupErrorUnlockIt, style: .default) { (_) in
self.delegate?.secureBackupSetupIntroViewControllerDidTapConnectToKeyBackup(self)
}
let resetAction = UIAlertAction(title: VectorL10n.secureKeyBackupSetupExistingBackupErrorDeleteIt, style: .destructive) { (_) in
self.deleteKeybackup()
}
let cancelAction = UIAlertAction(title: VectorL10n.cancel, style: .cancel) { (_) in
self.delegate?.secureBackupSetupIntroViewControllerDidCancel(self, showSkipAlert: false)
}
alertContoller.addAction(connectAction)
alertContoller.addAction(resetAction)
alertContoller.addAction(cancelAction)
self.present(alertContoller, animated: true)
}
}
}
// TODO: Move to view model
private func deleteKeybackup() {
guard let keyBackup = self.viewModel.keyBackup, let keybackupVersion = keyBackup.keyBackupVersion?.version else {
return
}
self.renderLoading()
keyBackup.deleteVersion(keybackupVersion, success: { [weak self] in
guard let self = self else {
return
}
self.renderLoaded()
self.checkKeyBackup()
}, failure: { [weak self] (error) in
guard let self = self else {
return
}
self.render(error: error)
})
}
}