Always sync and log push tokens. Apply OWSAlerts in more places.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent d0e68a8253
commit 716aa772f6

@ -20,6 +20,4 @@
#import <SignalServiceKit/OWSAnalytics.h> #import <SignalServiceKit/OWSAnalytics.h>
#import <SignalServiceKit/OWSDispatch.h> #import <SignalServiceKit/OWSDispatch.h>
#import <SignalServiceKit/iOSVersions.h> #import <SignalServiceKit/iOSVersions.h>
#define SignalAlertView(title,msg) [[[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:NSLocalizedString(@"OK", @"") otherButtonTitles:nil, nil] show]
#endif #endif

@ -11,7 +11,6 @@ class SyncPushTokensJob: NSObject {
let pushManager: PushManager let pushManager: PushManager
let accountManager: AccountManager let accountManager: AccountManager
let preferences: PropertyListPreferences let preferences: PropertyListPreferences
var uploadOnlyIfStale = true
required init(pushManager: PushManager, accountManager: AccountManager, preferences: PropertyListPreferences) { required init(pushManager: PushManager, accountManager: AccountManager, preferences: PropertyListPreferences) {
self.pushManager = pushManager self.pushManager = pushManager
@ -36,20 +35,13 @@ class SyncPushTokensJob: NSObject {
self.pushManager.validateUserNotificationSettings() self.pushManager.validateUserNotificationSettings()
let runPromise: Promise<Void> = self.requestPushTokens().then { (pushToken: String, voipToken: String) in let runPromise: Promise<Void> = self.requestPushTokens().then { (pushToken: String, voipToken: String) in
var shouldUploadTokens = !self.uploadOnlyIfStale
if self.preferences.getPushToken() != pushToken || self.preferences.getVoipToken() != voipToken { if self.preferences.getPushToken() != pushToken || self.preferences.getVoipToken() != voipToken {
Logger.debug("\(self.TAG) push tokens changed.") Logger.debug("\(self.TAG) push tokens changed.")
shouldUploadTokens = true
} }
guard shouldUploadTokens else { Logger.warn("\(self.TAG) Sending new tokens to account servers. pushToken: \(pushToken), voipToken: \(voipToken)")
Logger.info("\(self.TAG) skipping push token upload")
return Promise(value: ())
}
Logger.info("\(self.TAG) Sending new tokens to account servers.")
return self.accountManager.updatePushTokens(pushToken:pushToken, voipToken:voipToken).then { return self.accountManager.updatePushTokens(pushToken:pushToken, voipToken:voipToken).then {
Logger.info("\(self.TAG) Recording tokens locally.")
return self.recordNewPushTokens(pushToken:pushToken, voipToken:voipToken) return self.recordNewPushTokens(pushToken:pushToken, voipToken:voipToken)
} }
} }
@ -70,7 +62,7 @@ class SyncPushTokensJob: NSObject {
} }
private func recordNewPushTokens(pushToken: String, voipToken: String) -> Promise<Void> { private func recordNewPushTokens(pushToken: String, voipToken: String) -> Promise<Void> {
Logger.info("\(TAG) Recording new push tokens.") Logger.warn("\(TAG) Recording new push tokens. pushToken: \(pushToken), voipToken: \(voipToken)")
if (pushToken != self.preferences.getPushToken()) { if (pushToken != self.preferences.getPushToken()) {
Logger.info("\(TAG) Recording new plain push token") Logger.info("\(TAG) Recording new plain push token")

@ -134,15 +134,16 @@ typedef NS_ENUM(NSInteger, AdvancedSettingsTableViewControllerSection) {
[[OWSSyncPushTokensJob alloc] initWithPushManager:[PushManager sharedManager] [[OWSSyncPushTokensJob alloc] initWithPushManager:[PushManager sharedManager]
accountManager:[Environment getCurrent].accountManager accountManager:[Environment getCurrent].accountManager
preferences:[Environment preferences]]; preferences:[Environment preferences]];
syncJob.uploadOnlyIfStale = NO;
[syncJob run] [syncJob run]
.then(^{ .then(^{
DDLogDebug(@"%@ Successfully ran syncPushTokensJob.", self.tag); 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) { .catch(^(NSError *error) {
DDLogError(@"%@ Failed to run syncPushTokensJob with error: %@", self.tag, 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 { } else {

@ -372,13 +372,8 @@ NSString *const kCompletedRegistrationSegue = @"CompletedRegistration";
} }
- (void)showRegistrationErrorMessage:(NSError *)registrationError { - (void)showRegistrationErrorMessage:(NSError *)registrationError {
UIAlertView *registrationErrorAV = [[UIAlertView alloc] initWithTitle:registrationError.localizedDescription [OWSAlerts showAlertWithTitle:registrationError.localizedDescription
message:registrationError.localizedRecoverySuggestion message:registrationError.localizedRecoverySuggestion];
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK", @"")
otherButtonTitles:nil, nil];
[registrationErrorAV show];
} }
- (void)enableServerActions:(BOOL)enabled { - (void)enableServerActions:(BOOL)enabled {

@ -485,13 +485,8 @@ NS_ASSUME_NONNULL_BEGIN
@" https://itunes.apple.com/us/app/signal-private-messenger/id874139669?mt=8"]; @" https://itunes.apple.com/us/app/signal-private-messenger/id874139669?mt=8"];
[self presentViewController:picker animated:YES completion:[UIUtil modalCompletionBlock]]; [self presentViewController:picker animated:YES completion:[UIUtil modalCompletionBlock]];
} else { } else {
UIAlertView *notPermitted = [OWSAlerts showAlertWithTitle:NSLocalizedString(@"ALERT_ERROR_TITLE", @"")
[[UIAlertView alloc] initWithTitle:@"" message:NSLocalizedString(@"UNSUPPORTED_FEATURE_ERROR", @"")];
message:NSLocalizedString(@"UNSUPPORTED_FEATURE_ERROR", @"")
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK", @"")
otherButtonTitles:nil];
[notPermitted show];
} }
}]; }];

@ -11,6 +11,7 @@
#import "OWSContactsManager.h" #import "OWSContactsManager.h"
#import "OWSTableViewController.h" #import "OWSTableViewController.h"
#import "SecurityUtils.h" #import "SecurityUtils.h"
#import "Signal-Swift.h"
#import "SignalKeyingStorage.h" #import "SignalKeyingStorage.h"
#import "TSOutgoingMessage.h" #import "TSOutgoingMessage.h"
#import "UIUtil.h" #import "UIUtil.h"
@ -395,8 +396,11 @@ NS_ASSUME_NONNULL_BEGIN
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[self dismissViewControllerAnimated:YES [self dismissViewControllerAnimated:YES
completion:^{ completion:^{
SignalAlertView(NSLocalizedString(@"GROUP_CREATING_FAILED", nil), [OWSAlerts
error.localizedDescription); showAlertWithTitle:
NSLocalizedString(@"GROUP_CREATING_FAILED",
"Title of alert indicating that new group could not be created.")
message:error.localizedDescription];
}]; }];
}); });
}; };

@ -7,6 +7,7 @@
#import "Environment.h" #import "Environment.h"
#import "PhoneNumber.h" #import "PhoneNumber.h"
#import "PhoneNumberUtil.h" #import "PhoneNumberUtil.h"
#import "Signal-Swift.h"
#import "SignalKeyingStorage.h" #import "SignalKeyingStorage.h"
#import "TSAccountManager.h" #import "TSAccountManager.h"
#import "UIView+OWS.h" #import "UIView+OWS.h"
@ -148,10 +149,10 @@ static NSString *const kCodeSentSegue = @"codeSent";
} }
failure:^(NSError *error) { failure:^(NSError *error) {
if (error.code == 400) { if (error.code == 400) {
SignalAlertView(NSLocalizedString(@"REGISTRATION_ERROR", nil), [OWSAlerts showAlertWithTitle:NSLocalizedString(@"REGISTRATION_ERROR", nil)
NSLocalizedString(@"REGISTRATION_NON_VALID_NUMBER", )); message:NSLocalizedString(@"REGISTRATION_NON_VALID_NUMBER", nil)];
} else { } else {
SignalAlertView(error.localizedDescription, error.localizedRecoverySuggestion); [OWSAlerts showAlertWithTitle:error.localizedDescription message:error.localizedRecoverySuggestion];
} }
[_sendCodeButton setEnabled:YES]; [_sendCodeButton setEnabled:YES];
@ -166,14 +167,10 @@ static NSString *const kCodeSentSegue = @"codeSent";
} }
- (void)presentInvalidCountryCodeError { - (void)presentInvalidCountryCodeError {
UIAlertView *alertView = [OWSAlerts showAlertWithTitle:NSLocalizedString(@"REGISTER_CC_ERR_ALERT_VIEW_TITLE", @"")
[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"REGISTER_CC_ERR_ALERT_VIEW_TITLE", @"")
message:NSLocalizedString(@"REGISTER_CC_ERR_ALERT_VIEW_MESSAGE", @"") message:NSLocalizedString(@"REGISTER_CC_ERR_ALERT_VIEW_MESSAGE", @"")
delegate:nil buttonTitle:NSLocalizedString(
cancelButtonTitle:NSLocalizedString(@"DISMISS_BUTTON_TEXT", @"DISMISS_BUTTON_TEXT", @"Generic short text for button to dismiss a dialog")];
@"Generic short text for button to dismiss a dialog")
otherButtonTitles:nil];
[alertView show];
} }
#pragma mark - Keyboard notifications #pragma mark - Keyboard notifications

@ -46,7 +46,7 @@ typedef enum {
kUnregisterSection = 3, kUnregisterSection = 3,
} kSection; } kSection;
@interface SettingsTableViewController () <UIAlertViewDelegate> @interface SettingsTableViewController ()
@property (nonatomic, readonly) OWSContactsManager *contactsManager; @property (nonatomic, readonly) OWSContactsManager *contactsManager;
@ -246,18 +246,14 @@ typedef enum {
[Environment resetAppData]; [Environment resetAppData];
} }
failure:^(NSError *error) { failure:^(NSError *error) {
SignalAlertView(NSLocalizedString(@"UNREGISTER_SIGNAL_FAIL", @""), @""); [OWSAlerts showAlertWithTitle:NSLocalizedString(@"UNREGISTER_SIGNAL_FAIL", @"")];
}]; }];
} }
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == kNetworkStatusSection) { if (indexPath.section == kNetworkStatusSection) {
UIAlertView *info = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"NETWORK_STATUS_HEADER", @"") [OWSAlerts showAlertWithTitle:NSLocalizedString(@"NETWORK_STATUS_HEADER", @"")
message:NSLocalizedString(@"NETWORK_STATUS_TEXT", @"") message:NSLocalizedString(@"NETWORK_STATUS_TEXT", @"")];
delegate:self
cancelButtonTitle:NSLocalizedString(@"OK", @"")
otherButtonTitles:nil];
[info show];
} }
} }

@ -476,8 +476,11 @@ NSString *const SignalsViewControllerSegueShowIncomingCall = @"ShowIncomingCallS
failure:^(NSError *error) { failure:^(NSError *error) {
[self dismissViewControllerAnimated:YES [self dismissViewControllerAnimated:YES
completion:^{ completion:^{
SignalAlertView(NSLocalizedString(@"GROUP_REMOVING_FAILED", nil), [OWSAlerts
error.localizedRecoverySuggestion); showAlertWithTitle:
NSLocalizedString(@"GROUP_REMOVING_FAILED",
@"Title of alert indicating that group deletion failed.")
message:error.localizedRecoverySuggestion];
}]; }];
}]; }];
} else { } else {

@ -951,12 +951,9 @@ protocol CallServiceObserver: class {
// during a call while the app is in the background, because changing this // during a call while the app is in the background, because changing this
// permission kills the app. // permission kills the app.
if authStatus != .authorized { 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) OWSAlerts.showAlert(withTitle:NSLocalizedString("MISSING_CAMERA_PERMISSION_TITLE", comment: "Alert title when camera is not authorized"),
alert.show() message:NSLocalizedString("MISSING_CAMERA_PERMISSION_MESSAGE", comment: "Alert body when camera is not authorized"))
return return
} }

@ -20,9 +20,8 @@
@interface PushManager () @interface PushManager ()
@property TOCFutureSource *registerWithServerFutureSource; @property (nonatomic) TOCFutureSource *registerWithServerFutureSource;
@property UIAlertView *missingPermissionsAlertView; @property (nonatomic) NSMutableArray *currentNotifications;
@property (nonatomic, retain) NSMutableArray *currentNotifications;
@property (nonatomic) UIBackgroundTaskIdentifier callBackgroundTask; @property (nonatomic) UIBackgroundTaskIdentifier callBackgroundTask;
@property (nonatomic, readonly) OWSMessageSender *messageSender; @property (nonatomic, readonly) OWSMessageSender *messageSender;
@property (nonatomic, readonly) OWSMessageFetcherJob *messageFetcherJob; @property (nonatomic, readonly) OWSMessageFetcherJob *messageFetcherJob;
@ -69,11 +68,6 @@
networkManager:networkManager networkManager:networkManager
signalService:signalService]; 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; _callBackgroundTask = UIBackgroundTaskInvalid;
_currentNotifications = [NSMutableArray array]; _currentNotifications = [NSMutableArray array];

@ -23,15 +23,18 @@ import Foundation
UIApplication.shared.frontmostViewController?.present(alertController, animated: true, completion: nil) 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) { 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(title.characters.count > 0)
assert(message.characters.count > 0)
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) 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) UIApplication.shared.frontmostViewController?.present(alert, animated: true, completion: nil)
} }
} }

Loading…
Cancel
Save