From 544bdbd7f55bed5fe2b5422d77ba64a29d73b544 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 21 Nov 2018 11:54:32 -0800 Subject: [PATCH 1/2] Fix edge cases around registration. --- Signal/src/Models/AccountManager.swift | 7 ++++--- SignalMessaging/contacts/OWSSyncManager.m | 4 ++++ SignalServiceKit/src/Account/TSAccountManager.h | 3 +++ SignalServiceKit/src/Account/TSAccountManager.m | 10 ++++++++-- SignalServiceKit/src/Messages/OWSMessageSender.m | 14 +++++++++++++- 5 files changed, 32 insertions(+), 6 deletions(-) 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..d4f1baf2a 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -686,7 +686,19 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; failureHandlerParam(error); }; - TSThread *_Nullable thread = message.thread; + __block 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]] && From fa8095bf2dc08bedc25dad177581916d53b63cef Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 26 Nov 2018 10:00:25 -0500 Subject: [PATCH 2/2] Respond to CR. --- SignalServiceKit/src/Messages/OWSMessageSender.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index d4f1baf2a..3cf3d7629 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -686,7 +686,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; failureHandlerParam(error); }; - __block TSThread *_Nullable thread = message.thread; + TSThread *_Nullable thread = message.thread; BOOL isSyncMessage = [message isKindOfClass:[OWSOutgoingSyncMessage class]]; if (!thread && !isSyncMessage) {