diff --git a/Signal/src/Models/AccountManager.swift b/Signal/src/Models/AccountManager.swift index b3a1dd433..eda61a06c 100644 --- a/Signal/src/Models/AccountManager.swift +++ b/Signal/src/Models/AccountManager.swift @@ -19,8 +19,7 @@ public class AccountManager: NSObject { } @objc - public override init() - { + public override init() { super.init() SwiftSingletons.register(self) @@ -72,7 +71,9 @@ public class AccountManager: NSObject { default: throw error } - }.done { + }.then { (_) in + self.tsAccountManager.performUpdateAccountAttributes() + }.done { (_) in self.completeRegistration() } diff --git a/SignalMessaging/contacts/OWSSyncManager.m b/SignalMessaging/contacts/OWSSyncManager.m index bab197b47..6d05c22cf 100644 --- a/SignalMessaging/contacts/OWSSyncManager.m +++ b/SignalMessaging/contacts/OWSSyncManager.m @@ -226,6 +226,10 @@ NSString *const kSyncManagerLastContactSyncKey = @"kTSStorageManagerOWSSyncManag - (void)sendConfigurationSyncMessage_AppReady { DDLogInfo(@""); + if (![TSAccountManager sharedInstance].isRegistered) { + return; + } + BOOL areReadReceiptsEnabled = SSKEnvironment.shared.readReceiptManager.areReadReceiptsEnabled; BOOL showUnidentifiedDeliveryIndicators = Environment.shared.preferences.shouldShowUnidentifiedDeliveryIndicators; BOOL showTypingIndicators = self.typingIndicators.areTypingIndicatorsEnabled; diff --git a/SignalServiceKit/src/Account/TSAccountManager.h b/SignalServiceKit/src/Account/TSAccountManager.h index 523cd4919..f2c3dd821 100644 --- a/SignalServiceKit/src/Account/TSAccountManager.h +++ b/SignalServiceKit/src/Account/TSAccountManager.h @@ -144,6 +144,9 @@ extern NSString *const kNSNotificationName_LocalNumberDidChange; - (AnyPromise *)updateAccountAttributes; +// This should only be used during the registration process. +- (AnyPromise *)performUpdateAccountAttributes; + @end NS_ASSUME_NONNULL_END diff --git a/SignalServiceKit/src/Account/TSAccountManager.m b/SignalServiceKit/src/Account/TSAccountManager.m index 35586c0b6..ef5d9da2a 100644 --- a/SignalServiceKit/src/Account/TSAccountManager.m +++ b/SignalServiceKit/src/Account/TSAccountManager.m @@ -659,8 +659,7 @@ NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountMa if (!updateRequestDate) { return [AnyPromise promiseWithValue:@(1)]; } - - AnyPromise *promise = [[SignalServiceRestClient new] updateAccountAttributesObjC]; + AnyPromise *promise = [self performUpdateAccountAttributes]; promise = promise.then(^(id value) { [self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { // Clear the update request unless a new update has been requested @@ -673,7 +672,14 @@ NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountMa inCollection:TSAccountManager_UserAccountCollection]; } }]; + }); + return promise; +} +- (AnyPromise *)performUpdateAccountAttributes +{ + AnyPromise *promise = [[SignalServiceRestClient new] updateAccountAttributesObjC]; + promise = promise.then(^(id value) { // Fetch the local profile, as we may have changed its // account attributes. Specifically, we need to determine // if all devices for our account now support UD for sync diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index e327b7f0b..3cf3d7629 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -688,6 +688,18 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; TSThread *_Nullable thread = message.thread; + BOOL isSyncMessage = [message isKindOfClass:[OWSOutgoingSyncMessage class]]; + if (!thread && !isSyncMessage) { + OWSFailDebug(@"Missing thread for non-sync message."); + + // This thread has been deleted since the message was enqueued. + NSError *error = OWSErrorWithCodeDescription(OWSErrorCodeMessageSendNoValidRecipients, + NSLocalizedString(@"ERROR_DESCRIPTION_NO_VALID_RECIPIENTS", + @"Error indicating that an outgoing message had no valid recipients.")); + [error setIsRetryable:NO]; + return failureHandler(error); + } + // In the "self-send" special case, we ony need to send a sync message with a delivery receipt. if ([thread isKindOfClass:[TSContactThread class]] && [((TSContactThread *)thread).contactIdentifier isEqualToString:[TSAccountManager localNumber]]) {