From 716aa772f60df547c673004d550116097952c8dc Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 9 May 2017 10:04:48 -0400 Subject: [PATCH] Always sync and log push tokens. Apply OWSAlerts in more places. // FREEBIE --- Signal/Signal-Prefix.pch | 2 -- Signal/src/Models/SyncPushTokensJob.swift | 12 ++------ .../AdvancedSettingsTableViewController.m | 7 +++-- .../CodeVerificationViewController.m | 9 ++---- .../MessageComposeTableViewController.m | 9 ++---- .../ViewControllers/NewGroupViewController.m | 8 +++-- .../RegistrationViewController.m | 19 +++++------- .../SettingsTableViewController.m | 14 ++++----- .../ViewControllers/SignalsViewController.m | 29 ++++++++++--------- Signal/src/call/CallService.swift | 7 ++--- Signal/src/network/PushManager.m | 10 ++----- Signal/src/views/OWSAlerts.swift | 11 ++++--- 12 files changed, 56 insertions(+), 81 deletions(-) diff --git a/Signal/Signal-Prefix.pch b/Signal/Signal-Prefix.pch index fb20452f6..0c1572521 100644 --- a/Signal/Signal-Prefix.pch +++ b/Signal/Signal-Prefix.pch @@ -20,6 +20,4 @@ #import #import #import - - #define SignalAlertView(title,msg) [[[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:NSLocalizedString(@"OK", @"") otherButtonTitles:nil, nil] show] #endif diff --git a/Signal/src/Models/SyncPushTokensJob.swift b/Signal/src/Models/SyncPushTokensJob.swift index f5b11815b..a96f6ece5 100644 --- a/Signal/src/Models/SyncPushTokensJob.swift +++ b/Signal/src/Models/SyncPushTokensJob.swift @@ -11,7 +11,6 @@ class SyncPushTokensJob: NSObject { let pushManager: PushManager let accountManager: AccountManager let preferences: PropertyListPreferences - var uploadOnlyIfStale = true required init(pushManager: PushManager, accountManager: AccountManager, preferences: PropertyListPreferences) { self.pushManager = pushManager @@ -36,20 +35,13 @@ class SyncPushTokensJob: NSObject { self.pushManager.validateUserNotificationSettings() let runPromise: Promise = self.requestPushTokens().then { (pushToken: String, voipToken: String) in - var shouldUploadTokens = !self.uploadOnlyIfStale if self.preferences.getPushToken() != pushToken || self.preferences.getVoipToken() != voipToken { Logger.debug("\(self.TAG) push tokens changed.") - shouldUploadTokens = true } - guard shouldUploadTokens else { - Logger.info("\(self.TAG) skipping push token upload") - return Promise(value: ()) - } + Logger.warn("\(self.TAG) Sending new tokens to account servers. pushToken: \(pushToken), voipToken: \(voipToken)") - Logger.info("\(self.TAG) Sending new tokens to account servers.") return self.accountManager.updatePushTokens(pushToken:pushToken, voipToken:voipToken).then { - Logger.info("\(self.TAG) Recording tokens locally.") return self.recordNewPushTokens(pushToken:pushToken, voipToken:voipToken) } } @@ -70,7 +62,7 @@ class SyncPushTokensJob: NSObject { } private func recordNewPushTokens(pushToken: String, voipToken: String) -> Promise { - Logger.info("\(TAG) Recording new push tokens.") + Logger.warn("\(TAG) Recording new push tokens. pushToken: \(pushToken), voipToken: \(voipToken)") if (pushToken != self.preferences.getPushToken()) { Logger.info("\(TAG) Recording new plain push token") diff --git a/Signal/src/ViewControllers/AdvancedSettingsTableViewController.m b/Signal/src/ViewControllers/AdvancedSettingsTableViewController.m index 49483762a..a69ecb3bc 100644 --- a/Signal/src/ViewControllers/AdvancedSettingsTableViewController.m +++ b/Signal/src/ViewControllers/AdvancedSettingsTableViewController.m @@ -134,15 +134,16 @@ typedef NS_ENUM(NSInteger, AdvancedSettingsTableViewControllerSection) { [[OWSSyncPushTokensJob alloc] initWithPushManager:[PushManager sharedManager] accountManager:[Environment getCurrent].accountManager preferences:[Environment preferences]]; - syncJob.uploadOnlyIfStale = NO; [syncJob run] .then(^{ DDLogDebug(@"%@ Successfully ran syncPushTokensJob.", self.tag); - SignalAlertView(NSLocalizedString(@"PUSH_REGISTER_SUCCESS", @"Alert title"), nil); + [OWSAlerts showAlertWithTitle:NSLocalizedString(@"PUSH_REGISTER_SUCCESS", + @"Title of alert shown when push tokens sync job succeeds.")]; }) .catch(^(NSError *error) { DDLogError(@"%@ Failed to run syncPushTokensJob with error: %@", self.tag, error); - SignalAlertView(NSLocalizedString(@"REGISTRATION_BODY", @"Alert title"), error.localizedDescription); + [OWSAlerts showAlertWithTitle:NSLocalizedString(@"REGISTRATION_BODY", + @"Title of alert shown when push tokens sync job fails.")]; }); } else { diff --git a/Signal/src/ViewControllers/CodeVerificationViewController.m b/Signal/src/ViewControllers/CodeVerificationViewController.m index b37287ee2..995c3b8a4 100644 --- a/Signal/src/ViewControllers/CodeVerificationViewController.m +++ b/Signal/src/ViewControllers/CodeVerificationViewController.m @@ -372,13 +372,8 @@ NSString *const kCompletedRegistrationSegue = @"CompletedRegistration"; } - (void)showRegistrationErrorMessage:(NSError *)registrationError { - UIAlertView *registrationErrorAV = [[UIAlertView alloc] initWithTitle:registrationError.localizedDescription - message:registrationError.localizedRecoverySuggestion - delegate:nil - cancelButtonTitle:NSLocalizedString(@"OK", @"") - otherButtonTitles:nil, nil]; - - [registrationErrorAV show]; + [OWSAlerts showAlertWithTitle:registrationError.localizedDescription + message:registrationError.localizedRecoverySuggestion]; } - (void)enableServerActions:(BOOL)enabled { diff --git a/Signal/src/ViewControllers/MessageComposeTableViewController.m b/Signal/src/ViewControllers/MessageComposeTableViewController.m index 20570c337..94a95f40a 100644 --- a/Signal/src/ViewControllers/MessageComposeTableViewController.m +++ b/Signal/src/ViewControllers/MessageComposeTableViewController.m @@ -485,13 +485,8 @@ NS_ASSUME_NONNULL_BEGIN @" https://itunes.apple.com/us/app/signal-private-messenger/id874139669?mt=8"]; [self presentViewController:picker animated:YES completion:[UIUtil modalCompletionBlock]]; } else { - UIAlertView *notPermitted = - [[UIAlertView alloc] initWithTitle:@"" - message:NSLocalizedString(@"UNSUPPORTED_FEATURE_ERROR", @"") - delegate:nil - cancelButtonTitle:NSLocalizedString(@"OK", @"") - otherButtonTitles:nil]; - [notPermitted show]; + [OWSAlerts showAlertWithTitle:NSLocalizedString(@"ALERT_ERROR_TITLE", @"") + message:NSLocalizedString(@"UNSUPPORTED_FEATURE_ERROR", @"")]; } }]; diff --git a/Signal/src/ViewControllers/NewGroupViewController.m b/Signal/src/ViewControllers/NewGroupViewController.m index 0ad329d43..1aa11dacd 100644 --- a/Signal/src/ViewControllers/NewGroupViewController.m +++ b/Signal/src/ViewControllers/NewGroupViewController.m @@ -11,6 +11,7 @@ #import "OWSContactsManager.h" #import "OWSTableViewController.h" #import "SecurityUtils.h" +#import "Signal-Swift.h" #import "SignalKeyingStorage.h" #import "TSOutgoingMessage.h" #import "UIUtil.h" @@ -395,8 +396,11 @@ NS_ASSUME_NONNULL_BEGIN dispatch_async(dispatch_get_main_queue(), ^{ [self dismissViewControllerAnimated:YES completion:^{ - SignalAlertView(NSLocalizedString(@"GROUP_CREATING_FAILED", nil), - error.localizedDescription); + [OWSAlerts + showAlertWithTitle: + NSLocalizedString(@"GROUP_CREATING_FAILED", + "Title of alert indicating that new group could not be created.") + message:error.localizedDescription]; }]; }); }; diff --git a/Signal/src/ViewControllers/RegistrationViewController.m b/Signal/src/ViewControllers/RegistrationViewController.m index 6ffec001f..77d26514e 100644 --- a/Signal/src/ViewControllers/RegistrationViewController.m +++ b/Signal/src/ViewControllers/RegistrationViewController.m @@ -7,6 +7,7 @@ #import "Environment.h" #import "PhoneNumber.h" #import "PhoneNumberUtil.h" +#import "Signal-Swift.h" #import "SignalKeyingStorage.h" #import "TSAccountManager.h" #import "UIView+OWS.h" @@ -148,10 +149,10 @@ static NSString *const kCodeSentSegue = @"codeSent"; } failure:^(NSError *error) { if (error.code == 400) { - SignalAlertView(NSLocalizedString(@"REGISTRATION_ERROR", nil), - NSLocalizedString(@"REGISTRATION_NON_VALID_NUMBER", )); + [OWSAlerts showAlertWithTitle:NSLocalizedString(@"REGISTRATION_ERROR", nil) + message:NSLocalizedString(@"REGISTRATION_NON_VALID_NUMBER", nil)]; } else { - SignalAlertView(error.localizedDescription, error.localizedRecoverySuggestion); + [OWSAlerts showAlertWithTitle:error.localizedDescription message:error.localizedRecoverySuggestion]; } [_sendCodeButton setEnabled:YES]; @@ -166,14 +167,10 @@ static NSString *const kCodeSentSegue = @"codeSent"; } - (void)presentInvalidCountryCodeError { - UIAlertView *alertView = - [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"REGISTER_CC_ERR_ALERT_VIEW_TITLE", @"") - message:NSLocalizedString(@"REGISTER_CC_ERR_ALERT_VIEW_MESSAGE", @"") - delegate:nil - cancelButtonTitle:NSLocalizedString(@"DISMISS_BUTTON_TEXT", - @"Generic short text for button to dismiss a dialog") - otherButtonTitles:nil]; - [alertView show]; + [OWSAlerts showAlertWithTitle:NSLocalizedString(@"REGISTER_CC_ERR_ALERT_VIEW_TITLE", @"") + message:NSLocalizedString(@"REGISTER_CC_ERR_ALERT_VIEW_MESSAGE", @"") + buttonTitle:NSLocalizedString( + @"DISMISS_BUTTON_TEXT", @"Generic short text for button to dismiss a dialog")]; } #pragma mark - Keyboard notifications diff --git a/Signal/src/ViewControllers/SettingsTableViewController.m b/Signal/src/ViewControllers/SettingsTableViewController.m index 00917baae..fe2d4bd86 100644 --- a/Signal/src/ViewControllers/SettingsTableViewController.m +++ b/Signal/src/ViewControllers/SettingsTableViewController.m @@ -46,7 +46,7 @@ typedef enum { kUnregisterSection = 3, } kSection; -@interface SettingsTableViewController () +@interface SettingsTableViewController () @property (nonatomic, readonly) OWSContactsManager *contactsManager; @@ -243,21 +243,17 @@ typedef enum { - (void)proceedToUnregistration { [TSAccountManager unregisterTextSecureWithSuccess:^{ - [Environment resetAppData]; + [Environment resetAppData]; } failure:^(NSError *error) { - SignalAlertView(NSLocalizedString(@"UNREGISTER_SIGNAL_FAIL", @""), @""); + [OWSAlerts showAlertWithTitle:NSLocalizedString(@"UNREGISTER_SIGNAL_FAIL", @"")]; }]; } - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == kNetworkStatusSection) { - UIAlertView *info = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"NETWORK_STATUS_HEADER", @"") - message:NSLocalizedString(@"NETWORK_STATUS_TEXT", @"") - delegate:self - cancelButtonTitle:NSLocalizedString(@"OK", @"") - otherButtonTitles:nil]; - [info show]; + [OWSAlerts showAlertWithTitle:NSLocalizedString(@"NETWORK_STATUS_HEADER", @"") + message:NSLocalizedString(@"NETWORK_STATUS_TEXT", @"")]; } } diff --git a/Signal/src/ViewControllers/SignalsViewController.m b/Signal/src/ViewControllers/SignalsViewController.m index e2782a3cb..953fce5f0 100644 --- a/Signal/src/ViewControllers/SignalsViewController.m +++ b/Signal/src/ViewControllers/SignalsViewController.m @@ -467,19 +467,22 @@ NSString *const SignalsViewControllerSegueShowIncomingCall = @"ShowIncomingCallS inThread:thread groupMetaMessage:TSGroupMessageQuit]; [self.messageSender sendMessage:message - success:^{ - [self dismissViewControllerAnimated:YES - completion:^{ - [self deleteThread:thread]; - }]; - } - failure:^(NSError *error) { - [self dismissViewControllerAnimated:YES - completion:^{ - SignalAlertView(NSLocalizedString(@"GROUP_REMOVING_FAILED", nil), - error.localizedRecoverySuggestion); - }]; - }]; + success:^{ + [self dismissViewControllerAnimated:YES + completion:^{ + [self deleteThread:thread]; + }]; + } + failure:^(NSError *error) { + [self dismissViewControllerAnimated:YES + completion:^{ + [OWSAlerts + showAlertWithTitle: + NSLocalizedString(@"GROUP_REMOVING_FAILED", + @"Title of alert indicating that group deletion failed.") + message:error.localizedRecoverySuggestion]; + }]; + }]; } else { [self deleteThread:thread]; } diff --git a/Signal/src/call/CallService.swift b/Signal/src/call/CallService.swift index ff217c5a9..dbf0d91ae 100644 --- a/Signal/src/call/CallService.swift +++ b/Signal/src/call/CallService.swift @@ -951,12 +951,9 @@ protocol CallServiceObserver: class { // during a call while the app is in the background, because changing this // permission kills the app. if authStatus != .authorized { - let title = NSLocalizedString("MISSING_CAMERA_PERMISSION_TITLE", comment: "Alert title when camera is not authorized") - let message = NSLocalizedString("MISSING_CAMERA_PERMISSION_MESSAGE", comment: "Alert body when camera is not authorized") - let okButton = NSLocalizedString("OK", comment:"") - let alert = UIAlertView(title:title, message:message, delegate:nil, cancelButtonTitle:okButton) - alert.show() + OWSAlerts.showAlert(withTitle:NSLocalizedString("MISSING_CAMERA_PERMISSION_TITLE", comment: "Alert title when camera is not authorized"), + message:NSLocalizedString("MISSING_CAMERA_PERMISSION_MESSAGE", comment: "Alert body when camera is not authorized")) return } diff --git a/Signal/src/network/PushManager.m b/Signal/src/network/PushManager.m index 72bc687e7..71c4972a8 100644 --- a/Signal/src/network/PushManager.m +++ b/Signal/src/network/PushManager.m @@ -20,9 +20,8 @@ @interface PushManager () -@property TOCFutureSource *registerWithServerFutureSource; -@property UIAlertView *missingPermissionsAlertView; -@property (nonatomic, retain) NSMutableArray *currentNotifications; +@property (nonatomic) TOCFutureSource *registerWithServerFutureSource; +@property (nonatomic) NSMutableArray *currentNotifications; @property (nonatomic) UIBackgroundTaskIdentifier callBackgroundTask; @property (nonatomic, readonly) OWSMessageSender *messageSender; @property (nonatomic, readonly) OWSMessageFetcherJob *messageFetcherJob; @@ -69,11 +68,6 @@ networkManager:networkManager signalService:signalService]; - _missingPermissionsAlertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"ACTION_REQUIRED_TITLE", @"") - message:NSLocalizedString(@"PUSH_SETTINGS_MESSAGE", @"") - delegate:nil - cancelButtonTitle:NSLocalizedString(@"OK", @"") - otherButtonTitles:nil, nil]; _callBackgroundTask = UIBackgroundTaskInvalid; _currentNotifications = [NSMutableArray array]; diff --git a/Signal/src/views/OWSAlerts.swift b/Signal/src/views/OWSAlerts.swift index 24ebf0141..d75ebd3b4 100644 --- a/Signal/src/views/OWSAlerts.swift +++ b/Signal/src/views/OWSAlerts.swift @@ -23,15 +23,18 @@ import Foundation UIApplication.shared.frontmostViewController?.present(alertController, animated: true, completion: nil) } + public class func showAlert(withTitle title: String) { + self.showAlert(withTitle: title, message: nil, buttonTitle: NSLocalizedString("OK", comment: "")) + } + public class func showAlert(withTitle title: String, message: String) { - self.showAlert(withTitle: title, message: message, buttonLabel: NSLocalizedString("OK", comment: "")) + self.showAlert(withTitle: title, message: message, buttonTitle: NSLocalizedString("OK", comment: "")) } - public class func showAlert(withTitle title: String, message: String, buttonLabel: String) { + public class func showAlert(withTitle title: String, message: String?, buttonTitle: String) { assert(title.characters.count > 0) - assert(message.characters.count > 0) let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) - alert.addAction(UIAlertAction(title: buttonLabel, style: .default, handler: nil)) + alert.addAction(UIAlertAction(title: buttonTitle, style: .default, handler: nil)) UIApplication.shared.frontmostViewController?.present(alert, animated: true, completion: nil) } }