Merge branch 'charlesmchen/syncPushTokensOnLaunch'

pull/1/head
Matthew Chen 8 years ago
commit 18498eeda7

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

@ -24,7 +24,6 @@
#import "VersionMigrations.h" #import "VersionMigrations.h"
#import "ViewControllerUtils.h" #import "ViewControllerUtils.h"
#import <AxolotlKit/SessionCipher.h> #import <AxolotlKit/SessionCipher.h>
#import <PromiseKit/AnyPromise.h>
#import <SignalServiceKit/OWSDisappearingMessagesJob.h> #import <SignalServiceKit/OWSDisappearingMessagesJob.h>
#import <SignalServiceKit/OWSFailedAttachmentDownloadsJob.h> #import <SignalServiceKit/OWSFailedAttachmentDownloadsJob.h>
#import <SignalServiceKit/OWSFailedMessagesJob.h> #import <SignalServiceKit/OWSFailedMessagesJob.h>
@ -151,13 +150,8 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
[OWSSyncPushTokensJob runWithPushManager:[PushManager sharedManager] [OWSSyncPushTokensJob runWithPushManager:[PushManager sharedManager]
accountManager:[Environment getCurrent].accountManager accountManager:[Environment getCurrent].accountManager
preferences:[Environment preferences]] preferences:[Environment preferences]
.then(^{ showAlerts:NO];
DDLogDebug(@"%@ Successfully ran syncPushTokensJob.", self.tag);
})
.catch(^(NSError *_Nonnull error) {
DDLogError(@"%@ Failed to run syncPushTokensJob with error: %@", self.tag, error);
});
// Clean up any messages that expired since last launch. // Clean up any messages that expired since last launch.
[[[OWSDisappearingMessagesJob alloc] initWithStorageManager:[TSStorageManager sharedManager]] run]; [[[OWSDisappearingMessagesJob alloc] initWithStorageManager:[TSStorageManager sharedManager]] run];

@ -11,24 +11,21 @@ class SyncPushTokensJob: NSObject {
let pushManager: PushManager let pushManager: PushManager
let accountManager: AccountManager let accountManager: AccountManager
let preferences: PropertyListPreferences let preferences: PropertyListPreferences
var uploadOnlyIfStale = true 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.pushManager = pushManager
self.accountManager = accountManager self.accountManager = accountManager
self.preferences = preferences self.preferences = preferences
self.showAlerts = showAlerts
} }
@objc class func run(pushManager: PushManager, accountManager: AccountManager, preferences: PropertyListPreferences) -> AnyPromise { @objc class func run(pushManager: PushManager, accountManager: AccountManager, preferences: PropertyListPreferences, showAlerts: Bool = false) {
let job = self.init(pushManager: pushManager, accountManager: accountManager, preferences: preferences) let job = self.init(pushManager: pushManager, accountManager: accountManager, preferences: preferences, showAlerts:showAlerts)
return AnyPromise(job.run()) job.run()
} }
@objc func run() -> AnyPromise { func run() {
return AnyPromise(run())
}
func run() -> Promise<Void> {
Logger.debug("\(TAG) Starting.") Logger.debug("\(TAG) Starting.")
// Required to potentially prompt user for notifications settings // Required to potentially prompt user for notifications settings
@ -36,26 +33,29 @@ 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)
}
}.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()
return runPromise runPromise.retainUntilComplete()
} }
private func requestPushTokens() -> Promise<(pushToken: String, voipToken: String)> { private func requestPushTokens() -> Promise<(pushToken: String, voipToken: String)> {
@ -70,7 +70,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")

@ -10,7 +10,6 @@
#import "Signal-Swift.h" #import "Signal-Swift.h"
#import "TSAccountManager.h" #import "TSAccountManager.h"
#import "Pastelog.h" #import "Pastelog.h"
#import <PromiseKit/AnyPromise.h>
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@ -130,21 +129,10 @@ typedef NS_ENUM(NSInteger, AdvancedSettingsTableViewControllerSection) {
[DDLog flushLog]; [DDLog flushLog];
[Pastelog submitLogs]; [Pastelog submitLogs];
} else if ([tableView cellForRowAtIndexPath:indexPath] == self.registerPushCell) { } else if ([tableView cellForRowAtIndexPath:indexPath] == self.registerPushCell) {
OWSSyncPushTokensJob *syncJob = [OWSSyncPushTokensJob runWithPushManager:[PushManager sharedManager]
[[OWSSyncPushTokensJob alloc] initWithPushManager:[PushManager sharedManager] accountManager:[Environment getCurrent].accountManager
accountManager:[Environment getCurrent].accountManager preferences:[Environment preferences]
preferences:[Environment preferences]]; showAlerts:YES];
syncJob.uploadOnlyIfStale = NO;
[syncJob run]
.then(^{
DDLogDebug(@"%@ Successfully ran syncPushTokensJob.", self.tag);
SignalAlertView(NSLocalizedString(@"PUSH_REGISTER_SUCCESS", @"Alert title"), nil);
})
.catch(^(NSError *error) {
DDLogError(@"%@ Failed to run syncPushTokensJob with error: %@", self.tag, error);
SignalAlertView(NSLocalizedString(@"REGISTRATION_BODY", @"Alert title"), error.localizedDescription);
});
} else { } else {
DDLogDebug(@"%@ Ignoring cell selection at indexPath: %@", self.tag, indexPath); DDLogDebug(@"%@ Ignoring cell selection at indexPath: %@", self.tag, indexPath);
} }

@ -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", @"") buttonTitle:NSLocalizedString(
delegate:nil @"DISMISS_BUTTON_TEXT", @"Generic short text for button to dismiss a dialog")];
cancelButtonTitle:NSLocalizedString(@"DISMISS_BUTTON_TEXT",
@"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;
@ -243,21 +243,17 @@ typedef enum {
- (void)proceedToUnregistration { - (void)proceedToUnregistration {
[TSAccountManager unregisterTextSecureWithSuccess:^{ [TSAccountManager unregisterTextSecureWithSuccess:^{
[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];
} }
} }

@ -18,7 +18,6 @@
#import "TSStorageManager.h" #import "TSStorageManager.h"
#import "UIUtil.h" #import "UIUtil.h"
#import "VersionMigrations.h" #import "VersionMigrations.h"
#import <PromiseKit/AnyPromise.h>
#import <SignalServiceKit/OWSBlockingManager.h> #import <SignalServiceKit/OWSBlockingManager.h>
#import <SignalServiceKit/OWSMessageSender.h> #import <SignalServiceKit/OWSMessageSender.h>
#import <SignalServiceKit/TSMessagesManager.h> #import <SignalServiceKit/TSMessagesManager.h>
@ -339,13 +338,8 @@ NSString *const SignalsViewControllerSegueShowIncomingCall = @"ShowIncomingCallS
{ {
[OWSSyncPushTokensJob runWithPushManager:[PushManager sharedManager] [OWSSyncPushTokensJob runWithPushManager:[PushManager sharedManager]
accountManager:self.accountManager accountManager:self.accountManager
preferences:[Environment preferences]] preferences:[Environment preferences]
.then(^{ showAlerts:NO];
DDLogDebug(@"%@ Successfully ran syncPushTokensJob.", self.tag);
})
.catch(^(NSError *_Nonnull error) {
DDLogError(@"%@ Failed to run syncPushTokensJob with error: %@", self.tag, error);
});
} }
- (void)tableViewSetUp { - (void)tableViewSetUp {
@ -467,19 +461,22 @@ NSString *const SignalsViewControllerSegueShowIncomingCall = @"ShowIncomingCallS
inThread:thread inThread:thread
groupMetaMessage:TSGroupMessageQuit]; groupMetaMessage:TSGroupMessageQuit];
[self.messageSender sendMessage:message [self.messageSender sendMessage:message
success:^{ success:^{
[self dismissViewControllerAnimated:YES [self dismissViewControllerAnimated:YES
completion:^{ completion:^{
[self deleteThread:thread]; [self deleteThread:thread];
}]; }];
} }
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 {
[self deleteThread:thread]; [self deleteThread:thread];
} }

@ -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,21 @@ 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: nil)
}
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: nil)
} }
public class func showAlert(withTitle title: String, message: String, buttonLabel: String) { public class func showAlert(withTitle title: String, message: String? = nil, buttonTitle: String? = nil) {
assert(title.characters.count > 0) assert(title.characters.count > 0)
assert(message.characters.count > 0)
let actionTitle = (buttonTitle != nil ? buttonTitle : NSLocalizedString("OK", comment: ""))
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: actionTitle, 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