From 2f3831e04b1f8b8f36e17de61c971d2696a5700a Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 9 May 2017 10:45:20 -0400 Subject: [PATCH] Respond to CR. // FREEBIE --- Signal/src/AppDelegate.m | 3 ++- Signal/src/Models/SyncPushTokensJob.swift | 15 ++++++++++++--- .../AdvancedSettingsTableViewController.m | 3 ++- .../src/ViewControllers/SignalsViewController.m | 3 ++- Signal/src/views/OWSAlerts.swift | 11 +++++++---- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 207d8739c..d15c7a04b 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -150,7 +150,8 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; [OWSSyncPushTokensJob runWithPushManager:[PushManager sharedManager] accountManager:[Environment getCurrent].accountManager - preferences:[Environment preferences]]; + preferences:[Environment preferences] + showAlerts:NO]; // Clean up any messages that expired since last launch. [[[OWSDisappearingMessagesJob alloc] initWithStorageManager:[TSStorageManager sharedManager]] run]; diff --git a/Signal/src/Models/SyncPushTokensJob.swift b/Signal/src/Models/SyncPushTokensJob.swift index ea16d292f..25013e901 100644 --- a/Signal/src/Models/SyncPushTokensJob.swift +++ b/Signal/src/Models/SyncPushTokensJob.swift @@ -11,15 +11,17 @@ class SyncPushTokensJob: NSObject { let pushManager: PushManager let accountManager: AccountManager let preferences: PropertyListPreferences + let showAlerts: Bool - required init(pushManager: PushManager, accountManager: AccountManager, preferences: PropertyListPreferences) { + required init(pushManager: PushManager, accountManager: AccountManager, preferences: PropertyListPreferences, showAlerts: Bool) { self.pushManager = pushManager self.accountManager = accountManager self.preferences = preferences + self.showAlerts = showAlerts } - @objc class func run(pushManager: PushManager, accountManager: AccountManager, preferences: PropertyListPreferences) { - let job = self.init(pushManager: pushManager, accountManager: accountManager, preferences: preferences) + @objc class func run(pushManager: PushManager, accountManager: AccountManager, preferences: PropertyListPreferences, showAlerts: Bool = false) { + let job = self.init(pushManager: pushManager, accountManager: accountManager, preferences: preferences, showAlerts:showAlerts) job.run() } @@ -42,8 +44,15 @@ class SyncPushTokensJob: NSObject { } }.then { Logger.debug("\(self.TAG) Successfully ran syncPushTokensJob.") + if self.showAlerts { + OWSAlerts.showAlert(withTitle:NSLocalizedString("PUSH_REGISTER_SUCCESS", comment: "Title of alert shown when push tokens sync job succeeds.")) + } + return Promise(value: ()) }.catch { error in Logger.error("\(self.TAG) Failed to run syncPushTokensJob with error: \(error).") + if self.showAlerts { + OWSAlerts.showAlert(withTitle:NSLocalizedString("REGISTRATION_BODY", comment: "Title of alert shown when push tokens sync job fails.")) + } } runPromise.retainUntilComplete() diff --git a/Signal/src/ViewControllers/AdvancedSettingsTableViewController.m b/Signal/src/ViewControllers/AdvancedSettingsTableViewController.m index 7c6772d34..7d73f88e8 100644 --- a/Signal/src/ViewControllers/AdvancedSettingsTableViewController.m +++ b/Signal/src/ViewControllers/AdvancedSettingsTableViewController.m @@ -131,7 +131,8 @@ typedef NS_ENUM(NSInteger, AdvancedSettingsTableViewControllerSection) { } else if ([tableView cellForRowAtIndexPath:indexPath] == self.registerPushCell) { [OWSSyncPushTokensJob runWithPushManager:[PushManager sharedManager] accountManager:[Environment getCurrent].accountManager - preferences:[Environment preferences]]; + preferences:[Environment preferences] + showAlerts:YES]; } else { DDLogDebug(@"%@ Ignoring cell selection at indexPath: %@", self.tag, indexPath); } diff --git a/Signal/src/ViewControllers/SignalsViewController.m b/Signal/src/ViewControllers/SignalsViewController.m index 150e93e29..18c7f5a44 100644 --- a/Signal/src/ViewControllers/SignalsViewController.m +++ b/Signal/src/ViewControllers/SignalsViewController.m @@ -338,7 +338,8 @@ NSString *const SignalsViewControllerSegueShowIncomingCall = @"ShowIncomingCallS { [OWSSyncPushTokensJob runWithPushManager:[PushManager sharedManager] accountManager:self.accountManager - preferences:[Environment preferences]]; + preferences:[Environment preferences] + showAlerts:NO]; } - (void)tableViewSetUp { diff --git a/Signal/src/views/OWSAlerts.swift b/Signal/src/views/OWSAlerts.swift index d75ebd3b4..ce3644a49 100644 --- a/Signal/src/views/OWSAlerts.swift +++ b/Signal/src/views/OWSAlerts.swift @@ -24,17 +24,20 @@ import Foundation } public class func showAlert(withTitle title: String) { - self.showAlert(withTitle: title, message: nil, buttonTitle: NSLocalizedString("OK", comment: "")) + self.showAlert(withTitle: title, message: nil, buttonTitle: nil) } public class func showAlert(withTitle title: String, message: String) { - self.showAlert(withTitle: title, message: message, buttonTitle: NSLocalizedString("OK", comment: "")) + self.showAlert(withTitle: title, message: message, buttonTitle: nil) } - public class func showAlert(withTitle title: String, message: String?, buttonTitle: String) { + public class func showAlert(withTitle title: String, message: String? = nil, buttonTitle: String? = nil) { assert(title.characters.count > 0) + + let actionTitle = (buttonTitle != nil ? buttonTitle : NSLocalizedString("OK", comment: "")) + let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) - alert.addAction(UIAlertAction(title: buttonTitle, style: .default, handler: nil)) + alert.addAction(UIAlertAction(title: actionTitle, style: .default, handler: nil)) UIApplication.shared.frontmostViewController?.present(alert, animated: true, completion: nil) } }