diff --git a/Session/Signal/AppDelegate.m b/Session/Signal/AppDelegate.m index f02985166..ed8040a59 100644 --- a/Session/Signal/AppDelegate.m +++ b/Session/Signal/AppDelegate.m @@ -633,7 +633,7 @@ static NSTimeInterval launchStartedAt; if (isUsingFullAPNs) { __unused AnyPromise *promise = [LKPushNotificationAPI registerWithToken:deviceToken hexEncodedPublicKey:self.tsAccountManager.localNumber isForcedUpdate:NO]; } else { - __unused AnyPromise *promise = [LKPushNotificationAPI unregisterWithToken:deviceToken isForcedUpdate:NO]; + __unused AnyPromise *promise = [LKPushNotificationAPI unregisterToken:deviceToken]; } } @@ -817,7 +817,7 @@ static NSTimeInterval launchStartedAt; NSString *hexEncodedDeviceToken = [userDefaults stringForKey:@"deviceToken"]; if (isUsingFullAPNs && hexEncodedDeviceToken != nil) { NSData *deviceToken = [NSData dataFromHexString:hexEncodedDeviceToken]; - [[LKPushNotificationAPI unregisterWithToken:deviceToken isForcedUpdate:YES] retainUntilComplete]; + [[LKPushNotificationAPI unregisterToken:deviceToken] retainUntilComplete]; } [ThreadUtil deleteAllContent]; [SSKEnvironment.shared.identityManager clearIdentityKey]; diff --git a/Session/Utilities/Storage+Resetting.swift b/Session/Utilities/Storage+Resetting.swift new file mode 100644 index 000000000..ed132c393 --- /dev/null +++ b/Session/Utilities/Storage+Resetting.swift @@ -0,0 +1,23 @@ + +extension Storage { + + static func reset() { + let userDefaults = UserDefaults.standard + if userDefaults[.isUsingFullAPNs], let hexEncodedToken = userDefaults[.deviceToken] { + let token = Data(hex: hexEncodedToken) + PushNotificationAPI.unregister(token).retainUntilComplete() // TODO: Wait for this to complete? + } + + let appDelegate = UIApplication.shared.delegate as! AppDelegate + appDelegate.stopPoller() + appDelegate.stopClosedGroupPoller() + appDelegate.stopOpenGroupPollers() + + OWSStorage.resetAllStorage() + OWSUserProfile.resetProfileStorage() + Environment.shared.preferences.clear() + AppEnvironment.shared.notificationPresenter.clearAllNotifications() + + exit(0) + } +} diff --git a/Session/View Controllers/HomeVC.swift b/Session/View Controllers/HomeVC.swift index 8664d5f16..f342aa496 100644 --- a/Session/View Controllers/HomeVC.swift +++ b/Session/View Controllers/HomeVC.swift @@ -165,11 +165,11 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, UIScrol } private func showKeyPairMigrationNudgeIfNeeded() { - guard !KeyPairUtilities.hasV2KeyPair() else { return } +// 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 } +// guard nudge else { return } let sheet = KeyPairMigrationSheet() sheet.modalPresentationStyle = .overFullScreen sheet.modalTransitionStyle = .crossDissolve diff --git a/Session/View Controllers/KeyPairMigrationSheet.swift b/Session/View Controllers/KeyPairMigrationSheet.swift index 9240d81c4..12e2e0b40 100644 --- a/Session/View Controllers/KeyPairMigrationSheet.swift +++ b/Session/View Controllers/KeyPairMigrationSheet.swift @@ -61,7 +61,7 @@ final class KeyPairMigrationSheet : Sheet { 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 - NotificationCenter.default.post(name: .dataNukeRequested, object: nil) + Storage.reset() }) alert.addAction(UIAlertAction(title: "Cancel", style: .default, handler: nil)) presentingVC.dismiss(animated: true) { // Dismiss self first diff --git a/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift b/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift index a7076ad8c..e4783fc94 100644 --- a/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift +++ b/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift @@ -19,7 +19,7 @@ public final class PushNotificationAPI : NSObject { private override init() { } // MARK: Registration - static func unregister(with token: Data, isForcedUpdate: Bool) -> Promise { + public static func unregister(_ token: Data) -> Promise { let hexEncodedToken = token.toHexString() let parameters = [ "token" : hexEncodedToken ] let url = URL(string: "\(server)/unregister")! @@ -45,12 +45,12 @@ public final class PushNotificationAPI : NSObject { return promise } - @objc(unregisterWithToken:isForcedUpdate:) - public static func objc_unregister(with token: Data, isForcedUpdate: Bool) -> AnyPromise { - return AnyPromise.from(unregister(with: token, isForcedUpdate: isForcedUpdate)) + @objc(unregisterToken:) + public static func objc_unregister(token: Data) -> AnyPromise { + return AnyPromise.from(unregister(token)) } - static func register(with token: Data, publicKey: String, isForcedUpdate: Bool) -> Promise { + public static func register(with token: Data, publicKey: String, isForcedUpdate: Bool) -> Promise { let hexEncodedToken = token.toHexString() let userDefaults = UserDefaults.standard let oldToken = userDefaults[.deviceToken] diff --git a/SessionMessagingKit/To Do/TSAccountManager.m b/SessionMessagingKit/To Do/TSAccountManager.m index 2ee6e4b8c..03c1cfcc4 100644 --- a/SessionMessagingKit/To Do/TSAccountManager.m +++ b/SessionMessagingKit/To Do/TSAccountManager.m @@ -277,7 +277,7 @@ NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountMa BOOL isUsingFullAPNs = [NSUserDefaults.standardUserDefaults boolForKey:@"isUsingFullAPNs"]; NSData *pushTokenAsData = [NSData dataFromHexString:pushToken]; AnyPromise *promise = isUsingFullAPNs ? [LKPushNotificationAPI registerWithToken:pushTokenAsData hexEncodedPublicKey:self.localNumber isForcedUpdate:isForcedUpdate] - : [LKPushNotificationAPI unregisterWithToken:pushTokenAsData isForcedUpdate:isForcedUpdate]; + : [LKPushNotificationAPI unregisterToken:pushTokenAsData]; promise .then(^() { successHandler(); diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index d9f81cbd3..f038f3459 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -245,6 +245,7 @@ B8566C63256F55930045A0B9 /* OWSLinkPreview+Conversion.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8566C62256F55930045A0B9 /* OWSLinkPreview+Conversion.swift */; }; B8566C6C256F60F50045A0B9 /* OWSUserProfile.m in Sources */ = {isa = PBXBuildFile; fileRef = C38EF2D1255B6DAF007E1867 /* OWSUserProfile.m */; }; B8566C7D256F62030045A0B9 /* OWSUserProfile.h in Headers */ = {isa = PBXBuildFile; fileRef = C38EF2D3255B6DAF007E1867 /* OWSUserProfile.h */; settings = {ATTRIBUTES = (Public, ); }; }; + B85A68B12587141A008CC492 /* Storage+Resetting.swift in Sources */ = {isa = PBXBuildFile; fileRef = B85A68B02587141A008CC492 /* Storage+Resetting.swift */; }; B866CE112581C1A900535CC4 /* Sodium+Conversion.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3E7134E251C867C009649BB /* Sodium+Conversion.swift */; }; B86BD08423399ACF000F5AE3 /* Modal.swift in Sources */ = {isa = PBXBuildFile; fileRef = B86BD08323399ACF000F5AE3 /* Modal.swift */; }; B86BD08623399CEF000F5AE3 /* SeedModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = B86BD08523399CEF000F5AE3 /* SeedModal.swift */; }; @@ -1375,6 +1376,7 @@ B8544E3023D16CA500299F14 /* DeviceUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceUtilities.swift; sourceTree = ""; }; B8544E3223D50E4900299F14 /* AppearanceUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppearanceUtilities.swift; sourceTree = ""; }; B8566C62256F55930045A0B9 /* OWSLinkPreview+Conversion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OWSLinkPreview+Conversion.swift"; sourceTree = ""; }; + B85A68B02587141A008CC492 /* Storage+Resetting.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Storage+Resetting.swift"; sourceTree = ""; }; B86BD08323399ACF000F5AE3 /* Modal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modal.swift; sourceTree = ""; }; B86BD08523399CEF000F5AE3 /* SeedModal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeedModal.swift; sourceTree = ""; }; B8783E9D23EB948D00404FB8 /* UILabel+Interaction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UILabel+Interaction.swift"; sourceTree = ""; }; @@ -2605,6 +2607,7 @@ C31FFE56254A5FFE00F19441 /* KeyPairUtilities.swift */, B84664F4235022F30083A1CD /* MentionUtilities.swift */, B886B4A82398BA1500211ABE /* QRCode.swift */, + B85A68B02587141A008CC492 /* Storage+Resetting.swift */, B8783E9D23EB948D00404FB8 /* UILabel+Interaction.swift */, B83F2B87240CB75A000A54AB /* UIImage+Scaling.swift */, C31A6C59247F214E001123EF /* UIView+Glow.swift */, @@ -5432,6 +5435,7 @@ C396DAF42518408B00FF6DC5 /* Parser.swift in Sources */, 4C4AEC4520EC343B0020E72B /* DismissableTextField.swift in Sources */, 4CB5F26720F6E1E2004D1B42 /* MenuActionsViewController.swift in Sources */, + B85A68B12587141A008CC492 /* Storage+Resetting.swift in Sources */, 3496955E219B605E00DCFE74 /* PhotoLibrary.swift in Sources */, 45D231771DC7E8F10034FA89 /* SessionResetJob.swift in Sources */, 340FC8A9204DAC8D007AEB0F /* NotificationSettingsOptionsViewController.m in Sources */,