Merge branch 'charlesmchen/syncPushTokensOnLaunch'

This commit is contained in:
Matthew Chen 2017-05-09 10:45:41 -04:00
commit 18498eeda7
13 changed files with 84 additions and 123 deletions

View file

@ -20,6 +20,4 @@
#import <SignalServiceKit/OWSAnalytics.h>
#import <SignalServiceKit/OWSDispatch.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

View file

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

View file

@ -11,24 +11,21 @@ class SyncPushTokensJob: NSObject {
let pushManager: PushManager
let accountManager: AccountManager
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.accountManager = accountManager
self.preferences = preferences
self.showAlerts = showAlerts
}
@objc class func run(pushManager: PushManager, accountManager: AccountManager, preferences: PropertyListPreferences) -> AnyPromise {
let job = self.init(pushManager: pushManager, accountManager: accountManager, preferences: preferences)
return AnyPromise(job.run())
@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()
}
@objc func run() -> AnyPromise {
return AnyPromise(run())
}
func run() -> Promise<Void> {
func run() {
Logger.debug("\(TAG) Starting.")
// Required to potentially prompt user for notifications settings
@ -36,26 +33,29 @@ class SyncPushTokensJob: NSObject {
self.pushManager.validateUserNotificationSettings()
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 {
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)
}
}.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)> {
@ -70,7 +70,7 @@ class SyncPushTokensJob: NSObject {
}
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()) {
Logger.info("\(TAG) Recording new plain push token")

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -46,7 +46,7 @@ typedef enum {
kUnregisterSection = 3,
} kSection;
@interface SettingsTableViewController () <UIAlertViewDelegate>
@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", @"")];
}
}

View file

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

View file

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

View file

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

View file

@ -23,15 +23,21 @@ import Foundation
UIApplication.shared.frontmostViewController?.present(alertController, animated: true, completion: nil)
}
public class func showAlert(withTitle title: String, message: String) {
self.showAlert(withTitle: title, message: message, buttonLabel: NSLocalizedString("OK", comment: ""))
public class func showAlert(withTitle title: String) {
self.showAlert(withTitle: title, message: nil, buttonTitle: nil)
}
public class func showAlert(withTitle title: String, message: String, buttonLabel: String) {
public class func showAlert(withTitle title: String, message: String) {
self.showAlert(withTitle: title, message: message, buttonTitle: nil)
}
public class func showAlert(withTitle title: String, message: String? = nil, buttonTitle: String? = nil) {
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)
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)
}
}