From 1fa75ead5ddc035e4fbd15612d48cfb5ff089efe Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 2 Nov 2017 14:10:45 -0400 Subject: [PATCH] Respond to CR. // FREEBIE --- .../src/Messages/OWSMessageSender.m | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index 328e67c78..943224912 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -964,23 +964,38 @@ 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]); + __block BOOL hasSecondaryDevices; + [self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { + hasSecondaryDevices = [OWSDevice hasSecondaryDevicesWithTransaction:transaction]; + }]; + + BOOL hasDeviceMessages = deviceMessages.count > 0; + + if (!hasSecondaryDevices && !hasDeviceMessages) { + DDLogInfo(@"%@ Ignoring sync message without secondary devices: %@", self.tag, [message class]); OWSAssert([message isKindOfClass:[OWSOutgoingSyncMessage class]]); dispatch_async([OWSDispatch sendingQueue], ^{ + // This emulates the completion logic of an actual successful save (see below). [recipient save]; - [self handleMessageSentLocally:message]; successHandler(); }); return; + } else if (hasSecondaryDevices) { + // We may have just linked a new secondary device which is not yet reflected in + // the SignalRecipient that corresponds to ourself. Proceed. Client should learn + // of new secondary devices when this message send fails. + DDLogWarn(@"%@ sync message has no device messages but account has secondary devices.", self.tag); + } else if (hasDeviceMessages) { + OWSFail(@"%@ sync message has device messages for unknown secondary devices.", self.tag); + } else { + // Account has secondary devices; proceed as usual. } } else { OWSAssert(deviceMessages.count > 0); } - TSSubmitMessageRequest *request = [[TSSubmitMessageRequest alloc] initWithRecipient:recipient.uniqueId messages:deviceMessages relay:recipient.relay