diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 5f4b43fe3..268e80fcd 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -622,7 +622,7 @@ static NSTimeInterval launchStartedAt; - (void)enableBackgroundRefreshIfNecessary { [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. const NSTimeInterval kBackgroundRefreshInterval = 24 * 60 * 60; [[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:kBackgroundRefreshInterval]; diff --git a/Signal/src/util/Backup/OWSBackup.m b/Signal/src/util/Backup/OWSBackup.m index 4246256c0..9d43e6156 100644 --- a/Signal/src/util/Backup/OWSBackup.m +++ b/Signal/src/util/Backup/OWSBackup.m @@ -259,16 +259,11 @@ NSString *NSStringForBackupImportState(OWSBackupState state) if (!self.isBackupEnabled) { 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) { // Don't start backups when app is in the background. return NO; } - if (![self.tsAccountManager isRegistered]) { + if (![self.tsAccountManager isRegisteredAndReady]) { return NO; } return YES; diff --git a/SignalMessaging/contacts/OWSSyncManager.m b/SignalMessaging/contacts/OWSSyncManager.m index c94b5bdec..3dd8d2821 100644 --- a/SignalMessaging/contacts/OWSSyncManager.m +++ b/SignalMessaging/contacts/OWSSyncManager.m @@ -208,14 +208,14 @@ NSString *const kSyncManagerLastContactSyncKey = @"kTSStorageManagerOWSSyncManag return; } - if ([TSAccountManager sharedInstance].isRegistered) { + if ([TSAccountManager sharedInstance].isRegisteredAndReady) { [self sendSyncContactsMessageIfNecessary]; } } - (void)sendConfigurationSyncMessage { [AppReadiness runNowOrWhenAppDidBecomeReady:^{ - if (!self.tsAccountManager.isRegistered) { + if (!self.tsAccountManager.isRegisteredAndReady) { return; } @@ -226,7 +226,7 @@ NSString *const kSyncManagerLastContactSyncKey = @"kTSStorageManagerOWSSyncManag - (void)sendConfigurationSyncMessage_AppReady { DDLogInfo(@""); - if (![TSAccountManager sharedInstance].isRegistered) { + if (![TSAccountManager sharedInstance].isRegisteredAndReady) { return; } diff --git a/SignalServiceKit/src/Messages/OWSBatchMessageProcessor.m b/SignalServiceKit/src/Messages/OWSBatchMessageProcessor.m index 1ac05f937..8d6007c03 100644 --- a/SignalServiceKit/src/Messages/OWSBatchMessageProcessor.m +++ b/SignalServiceKit/src/Messages/OWSBatchMessageProcessor.m @@ -14,6 +14,7 @@ #import "OWSQueues.h" #import "OWSStorage.h" #import "SSKEnvironment.h" +#import "TSAccountManager.h" #import "TSDatabaseView.h" #import "TSErrorMessage.h" #import "TSYapDatabaseObject.h" @@ -267,6 +268,10 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo selector:@selector(applicationDidEnterBackground:) name:OWSApplicationDidEnterBackgroundNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(registrationStateDidChange:) + name:RegistrationStateDidChangeNotification + object:nil]; // Start processing. [AppReadiness runNowOrWhenAppDidBecomeReady:^{ @@ -292,6 +297,13 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo return SSKEnvironment.shared.messageManager; } +- (TSAccountManager *)tsAccountManager +{ + OWSAssertDebug(SSKEnvironment.shared.tsAccountManager); + + return SSKEnvironment.shared.tsAccountManager; +} + #pragma mark - Notifications - (void)applicationWillEnterForeground:(NSNotification *)notification @@ -304,6 +316,17 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo self.isAppInBackground = YES; } +- (void)registrationStateDidChange:(NSNotification *)notification +{ + OWSAssertIsOnMainThread(); + + [AppReadiness runNowOrWhenAppDidBecomeReady:^{ + if (CurrentAppContext().isMainApp) { + [self drainQueue]; + } + }]; +} + #pragma mark - instance methods - (dispatch_queue_t)serialQueue @@ -335,6 +358,9 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo if (!CurrentAppContext().isMainApp) { return; } + if (!self.tsAccountManager.isRegisteredAndReady) { + return; + } dispatch_async(self.serialQueue, ^{ if (self.isDrainingQueue) { diff --git a/SignalServiceKit/src/Messages/OWSMessageReceiver.m b/SignalServiceKit/src/Messages/OWSMessageReceiver.m index 4b484414d..8859ca8e4 100644 --- a/SignalServiceKit/src/Messages/OWSMessageReceiver.m +++ b/SignalServiceKit/src/Messages/OWSMessageReceiver.m @@ -14,6 +14,7 @@ #import "OWSQueues.h" #import "OWSStorage.h" #import "SSKEnvironment.h" +#import "TSAccountManager.h" #import "TSDatabaseView.h" #import "TSErrorMessage.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; } @@ -273,6 +279,26 @@ NSString *const OWSMessageDecryptJobFinderExtensionGroup = @"OWSMessageProcessin 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 - (dispatch_queue_t)serialQueue @@ -298,6 +324,9 @@ NSString *const OWSMessageDecryptJobFinderExtensionGroup = @"OWSMessageProcessin if (!CurrentAppContext().isMainApp) { return; } + if (!self.tsAccountManager.isRegisteredAndReady) { + return; + } dispatch_async(self.serialQueue, ^{ if (self.isDrainingQueue) {