diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index ba4b0f0bc..0b71dad4a 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -30,6 +30,7 @@ #import #import #import +#import #import #import #import @@ -809,6 +810,8 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; [[OWSBatchMessageProcessor sharedInstance] handleAnyUnprocessedEnvelopesAsync]; [OWSProfileManager.sharedManager fetchLocalUsersProfile]; + // Make sure this manager is started. + [OWSReadReceiptManager sharedManager]; } - (void)registrationStateDidChange diff --git a/SignalServiceKit/Utilities/precommit.py b/SignalServiceKit/Utilities/precommit.py index b1cc9640e..73f642bb4 100755 --- a/SignalServiceKit/Utilities/precommit.py +++ b/SignalServiceKit/Utilities/precommit.py @@ -114,13 +114,35 @@ def sort_include_block(text, filepath, filename, file_extension): for include in includes: include.isInclude = False + # Make sure matching header is first. + matching_header_includes = [] + other_includes = [] + def is_matching_header(include): + filename_wo_ext = os.path.splitext(filename)[0] + include_filename_wo_ext = os.path.splitext(os.path.basename(include.body))[0] + return filename_wo_ext == include_filename_wo_ext + for include in includes: + if is_matching_header(include): + matching_header_includes.append(include) + else: + other_includes.append(include) + includes = other_includes def formatBlock(includes): lines = [include.format() for include in includes] lines = list(set(lines)) def include_sorter(a, b): - return cmp(a.lower(), b.lower()) + # return cmp(a.lower(), b.lower()) + return cmp(a, b) + # print 'before' + # for line in lines: + # print '\t', line + # print lines.sort(include_sorter) + # print 'after' + # for line in lines: + # print '\t', line + # print # print # print 'filepath' # for line in lines: @@ -132,6 +154,8 @@ def sort_include_block(text, filepath, filename, file_extension): includeQuotes = [include for include in includes if include.isInclude and include.isQuote] importAngles = [include for include in includes if (not include.isInclude) and not include.isQuote] importQuotes = [include for include in includes if (not include.isInclude) and include.isQuote] + if matching_header_includes: + blocks.append(formatBlock(matching_header_includes)) if includeQuotes: blocks.append(formatBlock(includeQuotes)) if includeAngles: diff --git a/SignalServiceKit/src/Devices/OWSReadReceiptsProcessor.m b/SignalServiceKit/src/Devices/OWSReadReceiptsProcessor.m index ff86c4598..4088c10bf 100644 --- a/SignalServiceKit/src/Devices/OWSReadReceiptsProcessor.m +++ b/SignalServiceKit/src/Devices/OWSReadReceiptsProcessor.m @@ -59,14 +59,8 @@ NSString *const OWSReadReceiptsProcessorMarkedMessageAsReadNotification = - (instancetype)initWithIncomingMessage:(TSIncomingMessage *)message storageManager:(TSStorageManager *)storageManager { - // authorId isn't set on all legacy messages, so we take - // extra measures to ensure we obtain a valid value. - NSString *messageAuthorId; - if (message.authorId) { // Group Thread - messageAuthorId = message.authorId; - } else { // Contact Thread - messageAuthorId = [TSContactThread contactIdFromThreadId:message.uniqueThreadId]; - } + NSString *messageAuthorId = message.messageAuthorId; + OWSAssert(messageAuthorId.length > 0); OWSReadReceipt *readReceipt = [OWSReadReceipt firstWithSenderId:messageAuthorId timestamp:message.timestamp]; if (readReceipt) { diff --git a/SignalServiceKit/src/Messages/Interactions/TSIncomingMessage.h b/SignalServiceKit/src/Messages/Interactions/TSIncomingMessage.h index 1f0098d31..2eb3d4050 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSIncomingMessage.h +++ b/SignalServiceKit/src/Messages/Interactions/TSIncomingMessage.h @@ -103,11 +103,11 @@ NS_ASSUME_NONNULL_BEGIN timestamp:(uint64_t)timestamp transaction:(YapDatabaseReadWriteTransaction *)transaction; -@property (nonatomic, readonly) NSString *authorId; - // This will be 0 for messages created before we were tracking sourceDeviceId @property (nonatomic, readonly) UInt32 sourceDeviceId; +- (NSString *)messageAuthorId; + @end NS_ASSUME_NONNULL_END diff --git a/SignalServiceKit/src/Messages/Interactions/TSIncomingMessage.m b/SignalServiceKit/src/Messages/Interactions/TSIncomingMessage.m index f8585d074..45225acb5 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSIncomingMessage.m +++ b/SignalServiceKit/src/Messages/Interactions/TSIncomingMessage.m @@ -15,6 +15,8 @@ NS_ASSUME_NONNULL_BEGIN @interface TSIncomingMessage () +@property (nonatomic, readonly) NSString *authorId; + @property (nonatomic, getter=wasRead) BOOL read; @end @@ -91,15 +93,8 @@ NS_ASSUME_NONNULL_BEGIN if ([interaction isKindOfClass:[TSIncomingMessage class]]) { TSIncomingMessage *message = (TSIncomingMessage *)interaction; - // authorId isn't set on all legacy messages, so we take - // extra measures to ensure we obtain a valid value. - NSString *messageAuthorId; - if (message.authorId) { // Group Thread - messageAuthorId = message.authorId; - } else { // Contact Thread - messageAuthorId = - [TSContactThread contactIdFromThreadId:message.uniqueThreadId]; - } + NSString *messageAuthorId = message.messageAuthorId; + OWSAssert(messageAuthorId.length > 0); if ([messageAuthorId isEqualToString:authorId]) { foundMessage = message; @@ -111,6 +106,22 @@ NS_ASSUME_NONNULL_BEGIN return foundMessage; } +- (NSString *)messageAuthorId +{ + // authorId isn't set on all legacy messages, so we take + // extra measures to ensure we obtain a valid value. + NSString *messageAuthorId; + if (self.authorId) { + // Group Thread + messageAuthorId = self.authorId; + } else { + // Contact Thread + messageAuthorId = [TSContactThread contactIdFromThreadId:self.uniqueThreadId]; + } + OWSAssert(messageAuthorId.length > 0); + return messageAuthorId; +} + #pragma mark - OWSReadTracking - (BOOL)shouldAffectUnreadCounts @@ -138,8 +149,6 @@ NS_ASSUME_NONNULL_BEGIN } if (sendReadReceipt) { - // Notification must happen outside of the transaction, else we'll likely crash when the notification receiver - // tries to do anything with the DB. [OWSReadReceiptManager.sharedManager messageWasReadLocally:self]; } } diff --git a/SignalServiceKit/src/Messages/OWSDisappearingMessagesJob.m b/SignalServiceKit/src/Messages/OWSDisappearingMessagesJob.m index c7ef8beb4..6f57812cf 100644 --- a/SignalServiceKit/src/Messages/OWSDisappearingMessagesJob.m +++ b/SignalServiceKit/src/Messages/OWSDisappearingMessagesJob.m @@ -264,7 +264,7 @@ NS_ASSUME_NONNULL_BEGIN if ([message isKindOfClass:[TSIncomingMessage class]]) { TSIncomingMessage *incomingMessage = (TSIncomingMessage *)message; - NSString *contactName = [contactsManager displayNameForPhoneIdentifier:incomingMessage.authorId]; + NSString *contactName = [contactsManager displayNameForPhoneIdentifier:incomingMessage.messageAuthorId]; [[[OWSDisappearingConfigurationUpdateInfoMessage alloc] initWithTimestamp:message.timestamp thread:message.thread diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index 53b71953e..1695fcfd6 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -949,25 +949,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; } } - NSString *localNumber = [TSAccountManager localNumber]; - if ([localNumber isEqualToString:recipient.uniqueId]) { - if (deviceMessages.count < 1) { - DDLogInfo(@"Ignoring sync message without linked devices: %@", [message class]); - OWSAssert([message isKindOfClass:[OWSOutgoingSyncMessage class]]); - - dispatch_async([OWSDispatch sendingQueue], ^{ - [recipient save]; - [self handleMessageSentLocally:message]; - successHandler(); - }); - - return; - } - } else { - OWSAssert(deviceMessages.count > 0); - } - - TSSubmitMessageRequest *request = [[TSSubmitMessageRequest alloc] initWithRecipient:recipient.uniqueId messages:deviceMessages relay:recipient.relay diff --git a/SignalServiceKit/src/Messages/OWSReadReceiptManager.m b/SignalServiceKit/src/Messages/OWSReadReceiptManager.m index 3533a4bca..94b61392b 100644 --- a/SignalServiceKit/src/Messages/OWSReadReceiptManager.m +++ b/SignalServiceKit/src/Messages/OWSReadReceiptManager.m @@ -70,6 +70,11 @@ NS_ASSUME_NONNULL_BEGIN name:kNSNotificationName_DatabaseViewRegistrationComplete object:nil]; + // Try to start processing. + dispatch_async(dispatch_get_main_queue(), ^{ + [self scheduleProcessing]; + }); + return self; } @@ -119,7 +124,7 @@ NS_ASSUME_NONNULL_BEGIN { self.isProcessing = NO; - NSArray *readReceiptsToSend = [[self.toLinkedDevicesReadReceiptMap allValues] copy]; + NSArray *readReceiptsToSend = [self.toLinkedDevicesReadReceiptMap allValues]; [self.toLinkedDevicesReadReceiptMap removeAllObjects]; if (readReceiptsToSend.count > 0) { OWSReadReceiptsMessage *message = [[OWSReadReceiptsMessage alloc] initWithReadReceipts:readReceiptsToSend]; @@ -143,19 +148,10 @@ NS_ASSUME_NONNULL_BEGIN { @synchronized(self) { - NSString *threadUniqueId = message.thread.uniqueId; + NSString *threadUniqueId = message.uniqueThreadId; OWSAssert(threadUniqueId.length > 0); - // Only groupthread sets authorId, thus this crappy code. - // TODO Refactor so that ALL incoming messages have an authorId. - NSString *messageAuthorId; - if (message.authorId) { - // Group Thread - messageAuthorId = message.authorId; - } else { - // Contact Thread - messageAuthorId = [TSContactThread contactIdFromThreadId:message.uniqueThreadId]; - } + NSString *messageAuthorId = message.messageAuthorId; OWSAssert(messageAuthorId.length > 0); OWSReadReceipt *newReadReceipt =