Simplify code / pre-cache localNumber
Now that localNumber is read from a dedicated dbConnection we don't have to worry about it blocking. // FREEBIE
This commit is contained in:
parent
f99d4e9df9
commit
ed4de7e8af
|
@ -394,14 +394,13 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
|
|||
}
|
||||
DDLogInfo(@"Application opened with URL: %@", url);
|
||||
|
||||
[[TSAccountManager sharedInstance] ifRegistered:YES
|
||||
runAsync:^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// Wait up to N seconds for database view registrations to
|
||||
// complete.
|
||||
[self showImportUIForAttachment:attachment remainingRetries:5];
|
||||
});
|
||||
}];
|
||||
if ([TSAccountManager isRegistered]) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// Wait up to N seconds for database view registrations to
|
||||
// complete.
|
||||
[self showImportUIForAttachment:attachment remainingRetries:5];
|
||||
});
|
||||
}
|
||||
|
||||
return YES;
|
||||
} else {
|
||||
|
@ -455,70 +454,52 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
|
|||
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
RTCInitializeSSL();
|
||||
|
||||
if ([TSAccountManager isRegistered]) {
|
||||
// At this point, potentially lengthy DB locking migrations could be running.
|
||||
// Avoid blocking app launch by putting all further possible DB access in async block
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
DDLogInfo(
|
||||
@"%@ running post launch block for registered user: %@", self.tag, [TSAccountManager localNumber]);
|
||||
|
||||
// Clean up any messages that expired since last launch immediately
|
||||
// and continue cleaning in the background.
|
||||
[[OWSDisappearingMessagesJob sharedJob] startIfNecessary];
|
||||
|
||||
// Mark all "attempting out" messages as "unsent", i.e. any messages that were not successfully
|
||||
// sent before the app exited should be marked as failures.
|
||||
[[[OWSFailedMessagesJob alloc] initWithStorageManager:[TSStorageManager sharedManager]] run];
|
||||
[[[OWSFailedAttachmentDownloadsJob alloc] initWithStorageManager:[TSStorageManager sharedManager]] run];
|
||||
|
||||
[AppStoreRating setupRatingLibrary];
|
||||
});
|
||||
} else {
|
||||
DDLogInfo(@"%@ running post launch block for unregistered user.", self.tag);
|
||||
|
||||
// Unregistered user should have no unread messages. e.g. if you delete your account.
|
||||
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
|
||||
|
||||
[TSSocketManager requestSocketOpen];
|
||||
|
||||
UITapGestureRecognizer *gesture =
|
||||
[[UITapGestureRecognizer alloc] initWithTarget:[Pastelog class] action:@selector(submitLogs)];
|
||||
gesture.numberOfTapsRequired = 8;
|
||||
[self.window addGestureRecognizer:gesture];
|
||||
}
|
||||
}); // end dispatchOnce for first time we become active
|
||||
|
||||
// Every time we become active...
|
||||
if ([TSAccountManager isRegistered]) {
|
||||
// At this point, potentially lengthy DB locking migrations could be running.
|
||||
// Avoid blocking app launch by putting all further possible DB access in async thread.
|
||||
[[TSAccountManager sharedInstance]
|
||||
ifRegistered:YES
|
||||
runAsync:^{
|
||||
DDLogInfo(@"%@ running post launch block for registered user: %@",
|
||||
self.tag,
|
||||
[TSAccountManager localNumber]);
|
||||
|
||||
RTCInitializeSSL();
|
||||
|
||||
[OWSSyncPushTokensJob runWithPushManager:[PushManager sharedManager]
|
||||
accountManager:[Environment getCurrent].accountManager
|
||||
preferences:[Environment preferences]
|
||||
showAlerts:NO];
|
||||
|
||||
// Clean up any messages that expired since last launch immediately
|
||||
// and continue cleaning in the background.
|
||||
[[OWSDisappearingMessagesJob sharedJob] startIfNecessary];
|
||||
|
||||
// Mark all "attempting out" messages as "unsent", i.e. any messages that were not successfully
|
||||
// sent before the app exited should be marked as failures.
|
||||
[[[OWSFailedMessagesJob alloc] initWithStorageManager:[TSStorageManager sharedManager]] run];
|
||||
[[[OWSFailedAttachmentDownloadsJob alloc] initWithStorageManager:[TSStorageManager sharedManager]]
|
||||
run];
|
||||
|
||||
[AppStoreRating setupRatingLibrary];
|
||||
}];
|
||||
|
||||
[[TSAccountManager sharedInstance]
|
||||
ifRegistered:NO
|
||||
runAsync:^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
DDLogInfo(@"%@ running post launch block for unregistered user.", self.tag);
|
||||
|
||||
// Unregistered user should have no unread messages. e.g. if you delete your account.
|
||||
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
|
||||
|
||||
[TSSocketManager requestSocketOpen];
|
||||
|
||||
UITapGestureRecognizer *gesture =
|
||||
[[UITapGestureRecognizer alloc] initWithTarget:[Pastelog class]
|
||||
action:@selector(submitLogs)];
|
||||
gesture.numberOfTapsRequired = 8;
|
||||
[self.window addGestureRecognizer:gesture];
|
||||
});
|
||||
RTCInitializeSSL();
|
||||
}];
|
||||
});
|
||||
|
||||
[[TSAccountManager sharedInstance]
|
||||
ifRegistered:YES
|
||||
runAsync:^{
|
||||
[TSSocketManager requestSocketOpen];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[Environment getCurrent].contactsManager fetchSystemContactsIfAlreadyAuthorized];
|
||||
});
|
||||
|
||||
// This will fetch new messages, if we're using domain
|
||||
// fronting.
|
||||
[[PushManager sharedManager] applicationDidBecomeActive];
|
||||
}];
|
||||
// Avoid blocking app launch by putting all further possible DB access in async block
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[TSSocketManager requestSocketOpen];
|
||||
[[Environment getCurrent].contactsManager fetchSystemContactsIfAlreadyAuthorized];
|
||||
// This will fetch new messages, if we're using domain fronting.
|
||||
[[PushManager sharedManager] applicationDidBecomeActive];
|
||||
});
|
||||
}
|
||||
|
||||
DDLogInfo(@"%@ applicationDidBecomeActive completed.", self.tag);
|
||||
}
|
||||
|
|
|
@ -21,31 +21,27 @@ static NSString *const OWS103EnableVideoCallingMigrationId = @"103";
|
|||
- (void)runUp
|
||||
{
|
||||
DDLogWarn(@"%@ running migration...", self.tag);
|
||||
|
||||
// TODO: It'd be nice if TSAccountManager had a
|
||||
// [ifRegisteredRunAsync: ifNoRegisteredRunAsync:] method.
|
||||
[[TSAccountManager sharedInstance] ifRegistered:YES
|
||||
runAsync:^{
|
||||
TSUpdateAttributesRequest *request = [[TSUpdateAttributesRequest alloc]
|
||||
initWithUpdatedAttributesWithVoice];
|
||||
[[TSNetworkManager sharedManager] makeRequest:request
|
||||
success:^(NSURLSessionDataTask *task, id responseObject) {
|
||||
DDLogInfo(@"%@ successfully ran", self.tag);
|
||||
[self save];
|
||||
}
|
||||
failure:^(NSURLSessionDataTask *task, NSError *error) {
|
||||
if (!IsNSErrorNetworkFailure(error)) {
|
||||
OWSProdError([OWSAnalyticsEvents
|
||||
errorEnableVideoCallingRequestFailed]);
|
||||
}
|
||||
DDLogError(@"%@ failed with error: %@", self.tag, error);
|
||||
}];
|
||||
}];
|
||||
[[TSAccountManager sharedInstance] ifRegistered:NO
|
||||
runAsync:^{
|
||||
DDLogInfo(@"%@ skipping; not registered", self.tag);
|
||||
[self save];
|
||||
}];
|
||||
if ([TSAccountManager isRegistered]) {
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
TSUpdateAttributesRequest *request = [[TSUpdateAttributesRequest alloc] initWithUpdatedAttributesWithVoice];
|
||||
[[TSNetworkManager sharedManager] makeRequest:request
|
||||
success:^(NSURLSessionDataTask *task, id responseObject) {
|
||||
DDLogInfo(@"%@ successfully ran", self.tag);
|
||||
[self save];
|
||||
}
|
||||
failure:^(NSURLSessionDataTask *task, NSError *error) {
|
||||
if (!IsNSErrorNetworkFailure(error)) {
|
||||
OWSProdError([OWSAnalyticsEvents errorEnableVideoCallingRequestFailed]);
|
||||
}
|
||||
DDLogError(@"%@ failed with error: %@", self.tag, error);
|
||||
}];
|
||||
});
|
||||
} else {
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
DDLogInfo(@"%@ skipping; not registered", self.tag);
|
||||
[self save];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Logging
|
||||
|
|
|
@ -139,12 +139,9 @@ NSString *const kTSStorageManagerOWSContactsSyncingLastMessageKey =
|
|||
return;
|
||||
}
|
||||
|
||||
[[TSAccountManager sharedInstance] ifRegistered:YES
|
||||
runAsync:^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self sendSyncContactsMessageIfNecessary];
|
||||
});
|
||||
}];
|
||||
if ([TSAccountManager sharedInstance]) {
|
||||
[self sendSyncContactsMessageIfNecessary];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Logging
|
||||
|
|
|
@ -35,8 +35,6 @@ extern NSString *const kNSNotificationName_LocalNumberDidChange;
|
|||
*/
|
||||
+ (BOOL)isRegistered;
|
||||
|
||||
- (void)ifRegistered:(BOOL)isRegistered runAsync:(void (^)())block;
|
||||
|
||||
/**
|
||||
* Returns current phone number for this device, which may not yet have been registered.
|
||||
*
|
||||
|
|
|
@ -93,26 +93,6 @@ NSString *const TSAccountManager_LocalRegistrationIdKey = @"TSStorageLocalRegist
|
|||
return _isRegistered;
|
||||
}
|
||||
|
||||
- (void)ifRegistered:(BOOL)runIfRegistered runAsync:(void (^)())block
|
||||
{
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
if ([self isRegistered] == runIfRegistered) {
|
||||
if (runIfRegistered) {
|
||||
DDLogDebug(@"%@ Running existing-user block", self.tag);
|
||||
} else {
|
||||
DDLogDebug(@"%@ Running new-user block", self.tag);
|
||||
}
|
||||
block();
|
||||
} else {
|
||||
if (runIfRegistered) {
|
||||
DDLogDebug(@"%@ Skipping existing-user block for new-user", self.tag);
|
||||
} else {
|
||||
DDLogDebug(@"%@ Skipping new-user block for existing-user", self.tag);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)didRegister
|
||||
{
|
||||
DDLogInfo(@"%@ didRegister", self.tag);
|
||||
|
|
|
@ -109,10 +109,11 @@ static const NSTimeInterval kSignedPreKeyUpdateFailureMaxFailureDuration = 10 *
|
|||
// condition.
|
||||
lastPreKeyCheckTimestamp = [NSDate date];
|
||||
|
||||
[[TSAccountManager sharedInstance] ifRegistered:YES
|
||||
runAsync:^{
|
||||
[TSPreKeyManager checkPreKeys];
|
||||
}];
|
||||
if ([TSAccountManager isRegistered]) {
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
[TSPreKeyManager checkPreKeys];
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue