Merge branch 'mkirk/push-registration-blocks-signal-registration'

pull/1/head
Michael Kirk 8 years ago
commit 92ecf0cdc1

@ -462,6 +462,10 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
DDLogInfo( DDLogInfo(
@"%@ running post launch block for registered user: %@", self.tag, [TSAccountManager localNumber]); @"%@ running post launch block for registered user: %@", self.tag, [TSAccountManager localNumber]);
__unused AnyPromise *promise =
[OWSSyncPushTokensJob runWithPushManager:[PushManager sharedManager]
accountManager:[Environment getCurrent].accountManager
preferences:[Environment preferences]];
// Clean up any messages that expired since last launch immediately // Clean up any messages that expired since last launch immediately
// and continue cleaning in the background. // and continue cleaning in the background.

@ -13,10 +13,17 @@ class AccountManager: NSObject {
let TAG = "[AccountManager]" let TAG = "[AccountManager]"
let textSecureAccountManager: TSAccountManager let textSecureAccountManager: TSAccountManager
let networkManager: TSNetworkManager let networkManager: TSNetworkManager
let preferences: PropertyListPreferences
required init(textSecureAccountManager: TSAccountManager) { var pushManager: PushManager {
// dependency injection hack since PushManager has *alot* of dependencies, and would induce a cycle.
return PushManager.shared()
}
required init(textSecureAccountManager: TSAccountManager, preferences: PropertyListPreferences) {
self.networkManager = textSecureAccountManager.networkManager self.networkManager = textSecureAccountManager.networkManager
self.textSecureAccountManager = textSecureAccountManager self.textSecureAccountManager = textSecureAccountManager
self.preferences = preferences
} }
// MARK: registration // MARK: registration
@ -26,7 +33,7 @@ class AccountManager: NSObject {
} }
func register(verificationCode: String) -> Promise<Void> { func register(verificationCode: String) -> Promise<Void> {
return firstly { let registrationPromise = firstly {
Promise { fulfill, reject in Promise { fulfill, reject in
if verificationCode.characters.count == 0 { if verificationCode.characters.count == 0 {
let error = OWSErrorWithCodeDescription(.userError, let error = OWSErrorWithCodeDescription(.userError,
@ -39,9 +46,14 @@ class AccountManager: NSObject {
}.then { }.then {
Logger.debug("\(self.TAG) verification code looks well formed.") Logger.debug("\(self.TAG) verification code looks well formed.")
return self.registerForTextSecure(verificationCode: verificationCode) return self.registerForTextSecure(verificationCode: verificationCode)
}.then {
return SyncPushTokensJob.run(pushManager: self.pushManager, accountManager: self, preferences: self.preferences)
}.then { }.then {
Logger.debug("\(self.TAG) successfully registered for TextSecure") Logger.debug("\(self.TAG) successfully registered for TextSecure")
} }
registrationPromise.retainUntilComplete()
return registrationPromise
} }
private func registerForTextSecure(verificationCode: String) -> Promise<Void> { private func registerForTextSecure(verificationCode: String) -> Promise<Void> {

@ -11,22 +11,20 @@ class SyncPushTokensJob: NSObject {
let pushManager: PushManager let pushManager: PushManager
let accountManager: AccountManager let accountManager: AccountManager
let preferences: PropertyListPreferences let preferences: PropertyListPreferences
let showAlerts: Bool
var uploadOnlyIfStale = true var uploadOnlyIfStale = true
required init(pushManager: PushManager, accountManager: AccountManager, preferences: PropertyListPreferences, showAlerts: Bool) { required init(pushManager: PushManager, accountManager: AccountManager, preferences: PropertyListPreferences) {
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, showAlerts: Bool = false) { class func run(pushManager: PushManager, accountManager: AccountManager, preferences: PropertyListPreferences) -> Promise<Void> {
let job = self.init(pushManager: pushManager, accountManager: accountManager, preferences: preferences, showAlerts:showAlerts) let job = self.init(pushManager: pushManager, accountManager: accountManager, preferences: preferences)
job.run() return job.run()
} }
func run() { func run() -> Promise<Void> {
Logger.info("\(TAG) Starting.") Logger.info("\(TAG) Starting.")
// Required to potentially prompt user for notifications settings // Required to potentially prompt user for notifications settings
@ -61,21 +59,30 @@ class SyncPushTokensJob: NSObject {
return self.recordNewPushTokens(pushToken:pushToken, voipToken:voipToken) return self.recordNewPushTokens(pushToken:pushToken, voipToken:voipToken)
}.then { }.then {
Logger.debug("\(self.TAG) Successfully ran syncPushTokensJob.") 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 }.catch { error in
Logger.error("\(self.TAG) Failed to run syncPushTokensJob with error: \(error).") 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() runPromise.retainUntilComplete()
return runPromise
}
// MARK - objc wrappers, since objc can't use swift parameterized types
@objc class func run(pushManager: PushManager, accountManager: AccountManager, preferences: PropertyListPreferences) -> AnyPromise {
let promise: Promise<Void> = self.run(pushManager: pushManager, accountManager: accountManager, preferences: preferences)
return AnyPromise(promise)
}
@objc func run() -> AnyPromise {
let promise: Promise<Void> = self.run()
return AnyPromise(promise)
} }
// MARK - private helpers
private func requestPushTokens() -> Promise<(pushToken: String, voipToken: String)> { private func requestPushTokens() -> Promise<(pushToken: String, voipToken: String)> {
return Promise { fulfill, reject in return Promise { fulfill, reject in
self.pushManager.requestPushToken( self.pushManager.requestPushToken(

@ -12,6 +12,7 @@
#import "PushManager.h" #import "PushManager.h"
#import "Signal-Swift.h" #import "Signal-Swift.h"
#import "TSAccountManager.h" #import "TSAccountManager.h"
#import <PromiseKit/AnyPromise.h>
#import <Reachability/Reachability.h> #import <Reachability/Reachability.h>
#import <SignalServiceKit/OWSSignalService.h> #import <SignalServiceKit/OWSSignalService.h>
@ -242,10 +243,17 @@ NS_ASSUME_NONNULL_BEGIN
OWSSyncPushTokensJob *job = OWSSyncPushTokensJob *job =
[[OWSSyncPushTokensJob alloc] initWithPushManager:[PushManager sharedManager] [[OWSSyncPushTokensJob alloc] initWithPushManager:[PushManager sharedManager]
accountManager:[Environment getCurrent].accountManager accountManager:[Environment getCurrent].accountManager
preferences:[Environment preferences] preferences:[Environment preferences]];
showAlerts:YES];
job.uploadOnlyIfStale = NO; job.uploadOnlyIfStale = NO;
[job run]; [job run]
.then(^{
[OWSAlerts showAlertWithTitle:NSLocalizedString(@"PUSH_REGISTER_SUCCESS",
@"Title of alert shown when push tokens sync job succeeds.")];
})
.catch(^(NSError *error) {
[OWSAlerts showAlertWithTitle:NSLocalizedString(@"REGISTRATION_BODY",
@"Title of alert shown when push tokens sync job fails.")];
});
} }
- (void)didToggleEnableLogSwitch:(UISwitch *)sender { - (void)didToggleEnableLogSwitch:(UISwitch *)sender {

@ -485,8 +485,6 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
[self.editingDbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction * _Nonnull transaction) { [self.editingDbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction * _Nonnull transaction) {
[self.experienceUpgradeFinder markAllAsSeenWithTransaction:transaction]; [self.experienceUpgradeFinder markAllAsSeenWithTransaction:transaction];
}]; }];
[self ensureNotificationsUpToDate];
// Start running the disappearing messages job in case the newly registered user // Start running the disappearing messages job in case the newly registered user
// enables this feature // enables this feature
[[OWSDisappearingMessagesJob sharedJob] startIfNecessary]; [[OWSDisappearingMessagesJob sharedJob] startIfNecessary];
@ -533,14 +531,6 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
} }
} }
- (void)ensureNotificationsUpToDate
{
[OWSSyncPushTokensJob runWithPushManager:[PushManager sharedManager]
accountManager:self.accountManager
preferences:[Environment preferences]
showAlerts:NO];
}
- (void)tableViewSetUp { - (void)tableViewSetUp {
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
} }

@ -61,8 +61,8 @@ static Environment *environment = nil;
{ {
@synchronized (self) { @synchronized (self) {
if (!_accountManager) { if (!_accountManager) {
_accountManager = _accountManager = [[AccountManager alloc] initWithTextSecureAccountManager:[TSAccountManager sharedInstance]
[[AccountManager alloc] initWithTextSecureAccountManager:[TSAccountManager sharedInstance]]; preferences:self.preferences];
} }
} }

Loading…
Cancel
Save