Respond to CR.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-05-09 10:45:20 -04:00
parent dd3d63623a
commit 2f3831e04b
5 changed files with 25 additions and 10 deletions

View File

@ -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];

View File

@ -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()

View File

@ -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);
}

View File

@ -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 {

View File

@ -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)
}
}