From a9b76633203234981a160c21fdefdee50a2ae9a3 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Thu, 1 Aug 2019 10:34:32 +1000 Subject: [PATCH] Add clear all data option to settings --- .../AppSettings/AppSettingsViewController.m | 25 +++++++++++++++++++ .../translations/en.lproj/Localizable.strings | 3 +++ .../src/Loki/API/LokiAPI+SwarmAPI.swift | 4 +++ .../src/Messages/OWSIdentityManager.h | 1 + .../src/Messages/OWSIdentityManager.m | 6 +++++ 5 files changed, 39 insertions(+) diff --git a/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m b/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m index 6bdc616c4..fce6f189c 100644 --- a/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m +++ b/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m @@ -249,6 +249,12 @@ accessibilityIdentifier:ACCESSIBILITY_IDENTIFIER_WITH_NAME(self, @"show_seed") selector:@selector(showSeed) color:[UIColor ows_materialBlueColor]]]; + + [section + addItem:[self destructiveButtonItemWithTitle:NSLocalizedString(@"Clear All Data", @"") + accessibilityIdentifier:ACCESSIBILITY_IDENTIFIER_WITH_NAME(self, @"clear_all_data") + selector:@selector(clearAllData) + color:[UIColor ows_destructiveRedColor]]]; if (TSAccountManager.sharedInstance.isDeregistered) { [section addItem:[self destructiveButtonItemWithTitle:NSLocalizedString(@"SETTINGS_REREGISTER_BUTTON", @@ -522,6 +528,25 @@ [self presentAlert:alert]; } +- (void)clearAllData +{ + NSString *title = NSLocalizedString(@"Clear All Data", @""); + NSString *message = NSLocalizedString(@"Are you sure you want to clear all your data? This will delete your entire account, including all conversations and your personal key pair.", @""); + UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert]; + [alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"") style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { + [ThreadUtil deleteAllContent]; + [SSKEnvironment.shared.identityManager clearIdentityKey]; + [LKAPI clearRandomSnodePool]; + [LKAPI stopLongPolling]; + UIViewController *rootViewController = [[OnboardingController new] initialViewController]; + OWSNavigationController *navigationController = [[OWSNavigationController alloc] initWithRootViewController:rootViewController]; + navigationController.navigationBarHidden = YES; + UIApplication.sharedApplication.keyWindow.rootViewController = navigationController; + }]]; + [alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", @"") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { /* Do nothing */ }]]; + [self presentAlert:alert]; +} + - (void)reregisterUser { [RegistrationUtils showReregistrationUIFromViewController:self]; diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index fb8c81843..a46f26526 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -2600,3 +2600,6 @@ "Looks like you don't have any conversations yet. Get started by messaging a friend." = "Looks like you don't have any conversations yet. Get started by messaging a friend."; "Enter the public key of the person you'd like to securely message. They can share their public key with you by going into Loki Messenger's in-app settings and clicking \"Share Public Key\"." = "Enter the public key of the person you'd like to securely message. They can share their public key with you by going into Loki Messenger's in-app settings and clicking \"Share Public Key\"."; "Unlock Loki Messenger" = "Unlock Loki Messenger"; +"Clear All Data" = "Clear All Data"; +"Are you sure you want to clear all your data? This will delete your entire account, including all conversations and your personal key pair." = "Are you sure you want to clear all your data? This will delete your entire account, including all conversations and your personal key pair."; +"Cancel" = "Cancel"; diff --git a/SignalServiceKit/src/Loki/API/LokiAPI+SwarmAPI.swift b/SignalServiceKit/src/Loki/API/LokiAPI+SwarmAPI.swift index e92f6322a..cf4bfc8f9 100644 --- a/SignalServiceKit/src/Loki/API/LokiAPI+SwarmAPI.swift +++ b/SignalServiceKit/src/Loki/API/LokiAPI+SwarmAPI.swift @@ -41,6 +41,10 @@ public extension LokiAPI { // MARK: Clearnet Setup fileprivate static let seedNodePool: Set = [ "http://3.104.19.14:22023", "http://13.238.53.205:38157", "http://imaginary.stream:38157" ] fileprivate static var randomSnodePool: Set = [] + + @objc public static func clearRandomSnodePool() { + randomSnodePool.removeAll() + } // MARK: Internal API private static func getRandomSnode() -> Promise { diff --git a/SignalServiceKit/src/Messages/OWSIdentityManager.h b/SignalServiceKit/src/Messages/OWSIdentityManager.h index b436b717d..2e193192f 100644 --- a/SignalServiceKit/src/Messages/OWSIdentityManager.h +++ b/SignalServiceKit/src/Messages/OWSIdentityManager.h @@ -36,6 +36,7 @@ extern const NSUInteger kStoredIdentityKeyLength; + (instancetype)sharedManager; - (void)generateNewIdentityKey; +- (void)clearIdentityKey; - (void)setVerificationState:(OWSVerificationState)verificationState identityKey:(NSData *)identityKey diff --git a/SignalServiceKit/src/Messages/OWSIdentityManager.m b/SignalServiceKit/src/Messages/OWSIdentityManager.m index 2f22b1fad..b05cda119 100644 --- a/SignalServiceKit/src/Messages/OWSIdentityManager.m +++ b/SignalServiceKit/src/Messages/OWSIdentityManager.m @@ -124,6 +124,12 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa inCollection:OWSPrimaryStorageIdentityKeyStoreCollection]; } +- (void)clearIdentityKey +{ + [self.dbConnection removeObjectForKey:OWSPrimaryStorageIdentityKeyStoreIdentityKey + inCollection:OWSPrimaryStorageIdentityKeyStoreCollection]; +} + - (nullable NSData *)identityKeyForRecipientId:(NSString *)recipientId { __block NSData *_Nullable result = nil;