From 5b240da61976ca33767cf8697720c3e7e11ffc78 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Mon, 7 Dec 2020 16:27:29 +1100 Subject: [PATCH] Add Session ID change notice --- Session/Utilities/KeyPairUtilities.swift | 5 +++++ Session/View Controllers/NukeDataModal.swift | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Session/Utilities/KeyPairUtilities.swift b/Session/Utilities/KeyPairUtilities.swift index d5858ea38..8a0984808 100644 --- a/Session/Utilities/KeyPairUtilities.swift +++ b/Session/Utilities/KeyPairUtilities.swift @@ -20,4 +20,9 @@ enum KeyPairUtilities { dbConnection.setObject(ed25519KeyPair.publicKey.toHexString(), forKey: LKED25519PublicKey, inCollection: collection) dbConnection.setObject(x25519KeyPair, forKey: OWSPrimaryStorageIdentityKeyStoreIdentityKey, inCollection: collection) } + + static func hasV2KeyPair() -> Bool { + let dbConnection = OWSIdentityManager.shared().dbConnection + return (dbConnection.object(forKey: LKED25519SecretKey, inCollection: OWSPrimaryStorageIdentityKeyStoreCollection) != nil) + } } diff --git a/Session/View Controllers/NukeDataModal.swift b/Session/View Controllers/NukeDataModal.swift index c1b18419e..e45779346 100644 --- a/Session/View Controllers/NukeDataModal.swift +++ b/Session/View Controllers/NukeDataModal.swift @@ -49,7 +49,19 @@ final class NukeDataModal : Modal { // MARK: Interaction @objc private func nuke() { - UserDefaults.removeAll() // Not done in the nuke data implementation as unlinking requires this to happen later - NotificationCenter.default.post(name: .dataNukeRequested, object: nil) + func proceed() { + UserDefaults.removeAll() // Not done in the nuke data implementation as unlinking requires this to happen later + NotificationCenter.default.post(name: .dataNukeRequested, object: nil) + } + if KeyPairUtilities.hasV2KeyPair() { + proceed() + } else { + presentingViewController?.dismiss(animated: true, completion: nil) + let message = "We've upgraded the way Session IDs are generated, so your Session ID will be different if you choose to restore your account." + let alert = UIAlertController(title: "Are You Sure?", message: message, preferredStyle: .alert) + alert.addAction(UIAlertAction(title: "Yes", style: .destructive) { _ in proceed() }) + alert.addAction(UIAlertAction(title: "Cancel", style: .default, handler: nil)) + presentingViewController?.present(alert, animated: true, completion: nil) + } } }