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

// FREEBIE
This commit is contained in:
Matthew Chen 2017-05-09 10:04:48 -04:00
parent d0e68a8253
commit 716aa772f6
12 changed files with 57 additions and 82 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

@ -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<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)
}
}
@ -70,7 +62,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

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

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

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

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,18 @@ 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: NSLocalizedString("OK", comment: ""))
}
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: NSLocalizedString("OK", comment: ""))
}
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)
}
}