Don't consider registration complete until user registers their push
notification tokens. // FREEBIE
This commit is contained in:
parent
d41a9fd4d6
commit
2e83643327
|
@ -462,6 +462,10 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
|
|||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
DDLogInfo(
|
||||
@"%@ 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
|
||||
// and continue cleaning in the background.
|
||||
|
|
|
@ -13,10 +13,17 @@ class AccountManager: NSObject {
|
|||
let TAG = "[AccountManager]"
|
||||
let textSecureAccountManager: TSAccountManager
|
||||
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.textSecureAccountManager = textSecureAccountManager
|
||||
self.preferences = preferences
|
||||
}
|
||||
|
||||
// MARK: registration
|
||||
|
@ -26,7 +33,7 @@ class AccountManager: NSObject {
|
|||
}
|
||||
|
||||
func register(verificationCode: String) -> Promise<Void> {
|
||||
return firstly {
|
||||
let registrationPromise = firstly {
|
||||
Promise { fulfill, reject in
|
||||
if verificationCode.characters.count == 0 {
|
||||
let error = OWSErrorWithCodeDescription(.userError,
|
||||
|
@ -39,9 +46,14 @@ class AccountManager: NSObject {
|
|||
}.then {
|
||||
Logger.debug("\(self.TAG) verification code looks well formed.")
|
||||
return self.registerForTextSecure(verificationCode: verificationCode)
|
||||
}.then {
|
||||
return SyncPushTokensJob.run(pushManager: self.pushManager, accountManager: self, preferences: self.preferences)
|
||||
}.then {
|
||||
Logger.debug("\(self.TAG) successfully registered for TextSecure")
|
||||
}
|
||||
registrationPromise.retainUntilComplete()
|
||||
|
||||
return registrationPromise
|
||||
}
|
||||
|
||||
private func registerForTextSecure(verificationCode: String) -> Promise<Void> {
|
||||
|
|
|
@ -11,22 +11,20 @@ class SyncPushTokensJob: NSObject {
|
|||
let pushManager: PushManager
|
||||
let accountManager: AccountManager
|
||||
let preferences: PropertyListPreferences
|
||||
let showAlerts: Bool
|
||||
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.accountManager = accountManager
|
||||
self.preferences = preferences
|
||||
self.showAlerts = showAlerts
|
||||
}
|
||||
|
||||
@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()
|
||||
class func run(pushManager: PushManager, accountManager: AccountManager, preferences: PropertyListPreferences) -> Promise<Void> {
|
||||
let job = self.init(pushManager: pushManager, accountManager: accountManager, preferences: preferences)
|
||||
return job.run()
|
||||
}
|
||||
|
||||
func run() {
|
||||
func run() -> Promise<Void> {
|
||||
Logger.info("\(TAG) Starting.")
|
||||
|
||||
// Required to potentially prompt user for notifications settings
|
||||
|
@ -61,21 +59,30 @@ class SyncPushTokensJob: NSObject {
|
|||
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
|
||||
}
|
||||
|
||||
// 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)> {
|
||||
return Promise { fulfill, reject in
|
||||
self.pushManager.requestPushToken(
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#import "PushManager.h"
|
||||
#import "Signal-Swift.h"
|
||||
#import "TSAccountManager.h"
|
||||
#import <PromiseKit/AnyPromise.h>
|
||||
#import <Reachability/Reachability.h>
|
||||
#import <SignalServiceKit/OWSSignalService.h>
|
||||
|
||||
|
@ -242,10 +243,17 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
OWSSyncPushTokensJob *job =
|
||||
[[OWSSyncPushTokensJob alloc] initWithPushManager:[PushManager sharedManager]
|
||||
accountManager:[Environment getCurrent].accountManager
|
||||
preferences:[Environment preferences]
|
||||
showAlerts:YES];
|
||||
preferences:[Environment preferences]];
|
||||
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 {
|
||||
|
|
|
@ -485,8 +485,6 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
|
|||
[self.editingDbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction * _Nonnull transaction) {
|
||||
[self.experienceUpgradeFinder markAllAsSeenWithTransaction:transaction];
|
||||
}];
|
||||
[self ensureNotificationsUpToDate];
|
||||
|
||||
// Start running the disappearing messages job in case the newly registered user
|
||||
// enables this feature
|
||||
[[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 {
|
||||
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
}
|
||||
|
|
|
@ -61,8 +61,8 @@ static Environment *environment = nil;
|
|||
{
|
||||
@synchronized (self) {
|
||||
if (!_accountManager) {
|
||||
_accountManager =
|
||||
[[AccountManager alloc] initWithTextSecureAccountManager:[TSAccountManager sharedInstance]];
|
||||
_accountManager = [[AccountManager alloc] initWithTextSecureAccountManager:[TSAccountManager sharedInstance]
|
||||
preferences:self.preferences];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue