From aeea6f26de9cf568a58e2bac8af680768f4657ab Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Wed, 8 May 2019 15:51:08 +1000 Subject: [PATCH] Re-enable notifications --- Signal/src/AppDelegate.m | 18 ++++------ Signal/src/Models/AccountManager.swift | 33 ++++++++----------- .../AdvancedSettingsTableViewController.m | 23 ++++++------- 3 files changed, 30 insertions(+), 44 deletions(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 6f91ab602..97f66442c 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -732,12 +732,9 @@ static NSTimeInterval launchStartedAt; // usually sufficient, but e.g. on iOS11, users who have disabled "Allow Notifications" and disabled // "Background App Refresh" will not be able to obtain an APN token. Enabling those settings does not // restart the app, so we check every activation for users who haven't yet registered. - // Loki: Original code - // ======== -// __unused AnyPromise *promise = -// [OWSSyncPushTokensJob runWithAccountManager:AppEnvironment.shared.accountManager -// preferences:Environment.shared.preferences]; - // ======== + __unused AnyPromise *promise = + [OWSSyncPushTokensJob runWithAccountManager:AppEnvironment.shared.accountManager + preferences:Environment.shared.preferences]; } if ([OWS2FAManager sharedManager].isDueForReminder) { @@ -1249,12 +1246,9 @@ static NSTimeInterval launchStartedAt; [[AppEnvironment.shared.messageFetcherJob run] retainUntilComplete]; // This should happen at any launch, background or foreground. - // Loki: Original code - // ======== -// __unused AnyPromise *pushTokenpromise = -// [OWSSyncPushTokensJob runWithAccountManager:AppEnvironment.shared.accountManager -// preferences:Environment.shared.preferences]; - // ======== + __unused AnyPromise *pushTokenpromise = + [OWSSyncPushTokensJob runWithAccountManager:AppEnvironment.shared.accountManager + preferences:Environment.shared.preferences]; } [DeviceSleepManager.sharedInstance removeBlockWithBlockObject:self]; diff --git a/Signal/src/Models/AccountManager.swift b/Signal/src/Models/AccountManager.swift index 0aad4f790..bb825b7c3 100644 --- a/Signal/src/Models/AccountManager.swift +++ b/Signal/src/Models/AccountManager.swift @@ -59,25 +59,20 @@ public class AccountManager: NSObject { Logger.debug("registering with signal server") let registrationPromise: Promise = firstly { return self.registerForTextSecure(verificationCode: verificationCode, pin: pin) - } - // Loki: Original code - // ======== -// .then { _ -> Promise in -// return self.syncPushTokens().recover { (error) -> Promise in -// switch error { -// case PushRegistrationError.pushNotSupported(let description): -// // This can happen with: -// // - simulators, none of which support receiving push notifications -// // - on iOS11 devices which have disabled "Allow Notifications" and disabled "Enable Background Refresh" in the system settings. -// Logger.info("Recovered push registration error. Registering for manual message fetcher because push not supported: \(description)") -// return self.enableManualMessageFetching() -// default: -// throw error -// } -// } -// } - // ======== - .done { (_) -> Void in + }.then { _ -> Promise in + return self.syncPushTokens().recover { (error) -> Promise in + switch error { + case PushRegistrationError.pushNotSupported(let description): + // This can happen with: + // - simulators, none of which support receiving push notifications + // - on iOS11 devices which have disabled "Allow Notifications" and disabled "Enable Background Refresh" in the system settings. + Logger.info("Recovered push registration error. Registering for manual message fetcher because push not supported: \(description)") + return self.enableManualMessageFetching() + default: + throw error + } + } + }.done { (_) -> Void in self.completeRegistration() } diff --git a/Signal/src/ViewControllers/AppSettings/AdvancedSettingsTableViewController.m b/Signal/src/ViewControllers/AppSettings/AdvancedSettingsTableViewController.m index c35bf1366..251ebab6d 100644 --- a/Signal/src/ViewControllers/AppSettings/AdvancedSettingsTableViewController.m +++ b/Signal/src/ViewControllers/AppSettings/AdvancedSettingsTableViewController.m @@ -113,19 +113,16 @@ NS_ASSUME_NONNULL_BEGIN [contents addSection:loggingSection]; - // Loki: Original code - // ======== -// OWSTableSection *pushNotificationsSection = [OWSTableSection new]; -// pushNotificationsSection.headerTitle -// = NSLocalizedString(@"PUSH_REGISTER_TITLE", @"Used in table section header and alert view title contexts"); -// [pushNotificationsSection addItem:[OWSTableItem actionItemWithText:NSLocalizedString(@"REREGISTER_FOR_PUSH", nil) -// accessibilityIdentifier:ACCESSIBILITY_IDENTIFIER_WITH_NAME( -// self, @"reregister_push_notifications") -// actionBlock:^{ -// [weakSelf syncPushTokens]; -// }]]; -// [contents addSection:pushNotificationsSection]; - // ======== + OWSTableSection *pushNotificationsSection = [OWSTableSection new]; + pushNotificationsSection.headerTitle + = NSLocalizedString(@"PUSH_REGISTER_TITLE", @"Used in table section header and alert view title contexts"); + [pushNotificationsSection addItem:[OWSTableItem actionItemWithText:NSLocalizedString(@"REREGISTER_FOR_PUSH", nil) + accessibilityIdentifier:ACCESSIBILITY_IDENTIFIER_WITH_NAME( + self, @"reregister_push_notifications") + actionBlock:^{ + [weakSelf syncPushTokens]; + }]]; + [contents addSection:pushNotificationsSection]; // Censorship circumvention has certain disadvantages so it should only be // used if necessary. Therefore: