Add isRegisteredAndReady to TSAccountManager.

pull/1/head
Matthew Chen 7 years ago
parent 70b2280aa7
commit dcaaff7eac

@ -622,7 +622,7 @@ static NSTimeInterval launchStartedAt;
- (void)enableBackgroundRefreshIfNecessary - (void)enableBackgroundRefreshIfNecessary
{ {
[AppReadiness runNowOrWhenAppDidBecomeReady:^{ [AppReadiness runNowOrWhenAppDidBecomeReady:^{
if (OWS2FAManager.sharedManager.is2FAEnabled && [self.tsAccountManager isRegistered]) { if (OWS2FAManager.sharedManager.is2FAEnabled && [self.tsAccountManager isRegisteredAndReady]) {
// Ping server once a day to keep-alive 2FA clients. // Ping server once a day to keep-alive 2FA clients.
const NSTimeInterval kBackgroundRefreshInterval = 24 * 60 * 60; const NSTimeInterval kBackgroundRefreshInterval = 24 * 60 * 60;
[[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:kBackgroundRefreshInterval]; [[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:kBackgroundRefreshInterval];

@ -259,16 +259,11 @@ NSString *NSStringForBackupImportState(OWSBackupState state)
if (!self.isBackupEnabled) { if (!self.isBackupEnabled) {
return NO; return NO;
} }
if (self.hasPendingRestoreDecision) {
// Don't backup while awaiting user decision about
// whether to import previous backup.
return NO;
}
if (UIApplication.sharedApplication.applicationState != UIApplicationStateActive) { if (UIApplication.sharedApplication.applicationState != UIApplicationStateActive) {
// Don't start backups when app is in the background. // Don't start backups when app is in the background.
return NO; return NO;
} }
if (![self.tsAccountManager isRegistered]) { if (![self.tsAccountManager isRegisteredAndReady]) {
return NO; return NO;
} }
return YES; return YES;

@ -208,14 +208,14 @@ NSString *const kSyncManagerLastContactSyncKey = @"kTSStorageManagerOWSSyncManag
return; return;
} }
if ([TSAccountManager sharedInstance].isRegistered) { if ([TSAccountManager sharedInstance].isRegisteredAndReady) {
[self sendSyncContactsMessageIfNecessary]; [self sendSyncContactsMessageIfNecessary];
} }
} }
- (void)sendConfigurationSyncMessage { - (void)sendConfigurationSyncMessage {
[AppReadiness runNowOrWhenAppDidBecomeReady:^{ [AppReadiness runNowOrWhenAppDidBecomeReady:^{
if (!self.tsAccountManager.isRegistered) { if (!self.tsAccountManager.isRegisteredAndReady) {
return; return;
} }
@ -226,7 +226,7 @@ NSString *const kSyncManagerLastContactSyncKey = @"kTSStorageManagerOWSSyncManag
- (void)sendConfigurationSyncMessage_AppReady { - (void)sendConfigurationSyncMessage_AppReady {
DDLogInfo(@""); DDLogInfo(@"");
if (![TSAccountManager sharedInstance].isRegistered) { if (![TSAccountManager sharedInstance].isRegisteredAndReady) {
return; return;
} }

@ -14,6 +14,7 @@
#import "OWSQueues.h" #import "OWSQueues.h"
#import "OWSStorage.h" #import "OWSStorage.h"
#import "SSKEnvironment.h" #import "SSKEnvironment.h"
#import "TSAccountManager.h"
#import "TSDatabaseView.h" #import "TSDatabaseView.h"
#import "TSErrorMessage.h" #import "TSErrorMessage.h"
#import "TSYapDatabaseObject.h" #import "TSYapDatabaseObject.h"
@ -267,6 +268,10 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
selector:@selector(applicationDidEnterBackground:) selector:@selector(applicationDidEnterBackground:)
name:OWSApplicationDidEnterBackgroundNotification name:OWSApplicationDidEnterBackgroundNotification
object:nil]; object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(registrationStateDidChange:)
name:RegistrationStateDidChangeNotification
object:nil];
// Start processing. // Start processing.
[AppReadiness runNowOrWhenAppDidBecomeReady:^{ [AppReadiness runNowOrWhenAppDidBecomeReady:^{
@ -292,6 +297,13 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
return SSKEnvironment.shared.messageManager; return SSKEnvironment.shared.messageManager;
} }
- (TSAccountManager *)tsAccountManager
{
OWSAssertDebug(SSKEnvironment.shared.tsAccountManager);
return SSKEnvironment.shared.tsAccountManager;
}
#pragma mark - Notifications #pragma mark - Notifications
- (void)applicationWillEnterForeground:(NSNotification *)notification - (void)applicationWillEnterForeground:(NSNotification *)notification
@ -304,6 +316,17 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
self.isAppInBackground = YES; self.isAppInBackground = YES;
} }
- (void)registrationStateDidChange:(NSNotification *)notification
{
OWSAssertIsOnMainThread();
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
if (CurrentAppContext().isMainApp) {
[self drainQueue];
}
}];
}
#pragma mark - instance methods #pragma mark - instance methods
- (dispatch_queue_t)serialQueue - (dispatch_queue_t)serialQueue
@ -335,6 +358,9 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
if (!CurrentAppContext().isMainApp) { if (!CurrentAppContext().isMainApp) {
return; return;
} }
if (!self.tsAccountManager.isRegisteredAndReady) {
return;
}
dispatch_async(self.serialQueue, ^{ dispatch_async(self.serialQueue, ^{
if (self.isDrainingQueue) { if (self.isDrainingQueue) {

@ -14,6 +14,7 @@
#import "OWSQueues.h" #import "OWSQueues.h"
#import "OWSStorage.h" #import "OWSStorage.h"
#import "SSKEnvironment.h" #import "SSKEnvironment.h"
#import "TSAccountManager.h"
#import "TSDatabaseView.h" #import "TSDatabaseView.h"
#import "TSErrorMessage.h" #import "TSErrorMessage.h"
#import "TSYapDatabaseObject.h" #import "TSYapDatabaseObject.h"
@ -254,6 +255,11 @@ NSString *const OWSMessageDecryptJobFinderExtensionGroup = @"OWSMessageProcessin
} }
}]; }];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(registrationStateDidChange:)
name:RegistrationStateDidChangeNotification
object:nil];
return self; return self;
} }
@ -273,6 +279,26 @@ NSString *const OWSMessageDecryptJobFinderExtensionGroup = @"OWSMessageProcessin
return SSKEnvironment.shared.batchMessageProcessor; return SSKEnvironment.shared.batchMessageProcessor;
} }
- (TSAccountManager *)tsAccountManager
{
OWSAssertDebug(SSKEnvironment.shared.tsAccountManager);
return SSKEnvironment.shared.tsAccountManager;
}
#pragma mark - Notifications
- (void)registrationStateDidChange:(NSNotification *)notification
{
OWSAssertIsOnMainThread();
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
if (CurrentAppContext().isMainApp) {
[self drainQueue];
}
}];
}
#pragma mark - Instance methods #pragma mark - Instance methods
- (dispatch_queue_t)serialQueue - (dispatch_queue_t)serialQueue
@ -298,6 +324,9 @@ NSString *const OWSMessageDecryptJobFinderExtensionGroup = @"OWSMessageProcessin
if (!CurrentAppContext().isMainApp) { if (!CurrentAppContext().isMainApp) {
return; return;
} }
if (!self.tsAccountManager.isRegisteredAndReady) {
return;
}
dispatch_async(self.serialQueue, ^{ dispatch_async(self.serialQueue, ^{
if (self.isDrainingQueue) { if (self.isDrainingQueue) {

Loading…
Cancel
Save