From 475eb065389a243ff4f91eb455a6e8293b5f4ef0 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Mon, 11 Jan 2021 12:53:19 +1100 Subject: [PATCH] Make Session ID upgrades mandatory --- Session/View Controllers/HomeVC.swift | 5 ---- .../KeyPairMigrationSheet.swift | 30 +++++-------------- Session/View Controllers/Sheet.swift | 15 ++++++---- 3 files changed, 17 insertions(+), 33 deletions(-) diff --git a/Session/View Controllers/HomeVC.swift b/Session/View Controllers/HomeVC.swift index 359501ac4..46fa1786a 100644 --- a/Session/View Controllers/HomeVC.swift +++ b/Session/View Controllers/HomeVC.swift @@ -167,15 +167,10 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, UIScrol private func showKeyPairMigrationNudgeIfNeeded() { guard !KeyPairUtilities.hasV2KeyPair() else { return } - let lastNudge = UserDefaults.standard[.lastKeyPairMigrationNudge] - let nudgeInterval: Double = 3 * 24 * 60 * 60 // 3 days - let nudge = given(lastNudge) { Date().timeIntervalSince($0) > nudgeInterval } ?? true - guard nudge else { return } let sheet = KeyPairMigrationSheet() sheet.modalPresentationStyle = .overFullScreen sheet.modalTransitionStyle = .crossDissolve present(sheet, animated: true, completion: nil) - UserDefaults.standard[.lastKeyPairMigrationNudge] = Date() } private func showKeyPairMigrationSuccessModalIfNeeded() { diff --git a/Session/View Controllers/KeyPairMigrationSheet.swift b/Session/View Controllers/KeyPairMigrationSheet.swift index 9c4c45c01..5c096b924 100644 --- a/Session/View Controllers/KeyPairMigrationSheet.swift +++ b/Session/View Controllers/KeyPairMigrationSheet.swift @@ -1,6 +1,8 @@ final class KeyPairMigrationSheet : Sheet { + override class var isDismissable: Bool { false } + override func populateContentView() { // Image view let imageView = UIImageView(image: #imageLiteral(resourceName: "Shield").withTint(Colors.text)) @@ -12,6 +14,7 @@ final class KeyPairMigrationSheet : Sheet { titleLabel.textColor = Colors.text titleLabel.font = .boldSystemFont(ofSize: isIPhone5OrSmaller ? Values.largeFontSize : Values.veryLargeFontSize) titleLabel.text = "Session IDs Just Got Better" + titleLabel.textAlignment = .center titleLabel.numberOfLines = 0 titleLabel.lineBreakMode = .byWordWrapping // Top stack view @@ -25,9 +28,9 @@ final class KeyPairMigrationSheet : Sheet { explanationLabel.font = .systemFont(ofSize: Values.smallFontSize) explanationLabel.textAlignment = .center explanationLabel.text = """ - We’ve upgraded Session IDs to make them even more private and secure. We recommend upgrading to a new Session ID now. + We’ve upgraded Session IDs to make them even more private and secure. To ensure your continued privacy you're now required to upgrade. - You will lose existing contacts and conversations, but you’ll gain even more privacy and security. You will need to upgrade your Session ID eventually, but you can choose to delay the upgrade if you need to save contacts or conversations. + Your existing contacts and conversations will be lost, but you’ll be able to use Session knowing you have the best privacy and security possible. """ explanationLabel.numberOfLines = 0 explanationLabel.lineBreakMode = .byWordWrapping @@ -36,18 +39,8 @@ final class KeyPairMigrationSheet : Sheet { upgradeNowButton.set(.width, to: 240) upgradeNowButton.setTitle("Upgrade Now", for: UIControl.State.normal) upgradeNowButton.addTarget(self, action: #selector(upgradeNow), for: UIControl.Event.touchUpInside) - // Upgrade later button - let upgradeLaterButton = Button(style: .prominentOutline, size: .large) - upgradeLaterButton.set(.width, to: 240) - upgradeLaterButton.setTitle("Upgrade Later", for: UIControl.State.normal) - upgradeLaterButton.addTarget(self, action: #selector(close), for: UIControl.Event.touchUpInside) - // Button stack view - let buttonStackView = UIStackView(arrangedSubviews: [ upgradeNowButton, upgradeLaterButton ]) - buttonStackView.axis = .vertical - buttonStackView.spacing = Values.mediumSpacing - buttonStackView.alignment = .center // Main stack view - let stackView = UIStackView(arrangedSubviews: [ topStackView, explanationLabel, buttonStackView ]) + let stackView = UIStackView(arrangedSubviews: [ topStackView, explanationLabel, upgradeNowButton ]) stackView.axis = .vertical stackView.spacing = Values.veryLargeSpacing stackView.alignment = .center @@ -60,15 +53,6 @@ final class KeyPairMigrationSheet : Sheet { } @objc private func upgradeNow() { - guard let presentingVC = presentingViewController else { return } - let message = "You’re upgrading to a new Session ID. This will give you improved privacy and security, but it will clear ALL app data. Contacts and conversations will be lost. Proceed?" - let alert = UIAlertController(title: "Upgrade Session ID?", message: message, preferredStyle: .alert) - alert.addAction(UIAlertAction(title: "Yes", style: .destructive) { _ in - Storage.prepareForV2KeyPairMigration() - }) - alert.addAction(UIAlertAction(title: "Cancel", style: .default, handler: nil)) - presentingVC.dismiss(animated: true) { // Dismiss self first - presentingVC.present(alert, animated: true, completion: nil) - } + Storage.prepareForV2KeyPairMigration() } } diff --git a/Session/View Controllers/Sheet.swift b/Session/View Controllers/Sheet.swift index d68eda8d2..f9cc8056a 100644 --- a/Session/View Controllers/Sheet.swift +++ b/Session/View Controllers/Sheet.swift @@ -4,7 +4,8 @@ class Sheet : BaseVC { // MARK: Settings let overshoot: CGFloat = 40 - + class var isDismissable: Bool { true } + // MARK: Components lazy var contentView: UIView = { let result = UIView() @@ -24,9 +25,11 @@ class Sheet : BaseVC { super.viewDidLoad() let alpha = isLightMode ? CGFloat(0.1) : Values.modalBackgroundOpacity view.backgroundColor = UIColor(hex: 0x000000).withAlphaComponent(alpha) - let swipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(close)) - swipeGestureRecognizer.direction = .down - view.addGestureRecognizer(swipeGestureRecognizer) + if type(of: self).isDismissable { + let swipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(close)) + swipeGestureRecognizer.direction = .down + view.addGestureRecognizer(swipeGestureRecognizer) + } setUpViewHierarchy() } @@ -50,7 +53,9 @@ class Sheet : BaseVC { if contentView.frame.contains(location) { super.touchesBegan(touches, with: event) } else { - close() + if type(of: self).isDismissable { + close() + } } }