From 77e0c9664c413a1a44ebea0a3bf2e0d1e1e90576 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 21 Sep 2017 17:25:13 -0400 Subject: [PATCH] Respond to CR. // FREEBIE --- .../src/Messages/Interactions/TSInteraction.m | 2 ++ .../src/Messages/OWSDisappearingMessagesJob.m | 8 ++++---- SignalServiceKit/src/Messages/OWSMessageManager.m | 2 +- SignalServiceKit/src/Messages/OWSMessageSender.m | 14 +++++++++----- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/SignalServiceKit/src/Messages/Interactions/TSInteraction.m b/SignalServiceKit/src/Messages/Interactions/TSInteraction.m index f7bb4d15a..6084622da 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSInteraction.m +++ b/SignalServiceKit/src/Messages/Interactions/TSInteraction.m @@ -43,6 +43,8 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithTimestamp:(uint64_t)timestamp inThread:(TSThread *)thread { + OWSAssert(timestamp > 0); + self = [super initWithUniqueId:nil]; if (!self) { diff --git a/SignalServiceKit/src/Messages/OWSDisappearingMessagesJob.m b/SignalServiceKit/src/Messages/OWSDisappearingMessagesJob.m index 3d6d6f04b..a3cb33ccf 100644 --- a/SignalServiceKit/src/Messages/OWSDisappearingMessagesJob.m +++ b/SignalServiceKit/src/Messages/OWSDisappearingMessagesJob.m @@ -266,14 +266,14 @@ NS_ASSUME_NONNULL_BEGIN TSIncomingMessage *incomingMessage = (TSIncomingMessage *)message; NSString *contactName = [contactsManager displayNameForPhoneIdentifier:incomingMessage.messageAuthorId]; - // We want the info message to appear after the message. - [[[OWSDisappearingConfigurationUpdateInfoMessage alloc] initWithTimestamp:message.timestamp + 1 + // We want the info message to appear _before_ the message. + [[[OWSDisappearingConfigurationUpdateInfoMessage alloc] initWithTimestamp:message.timestamp - 1 thread:message.thread configuration:disappearingMessagesConfiguration createdByRemoteName:contactName] save]; } else { - // We want the info message to appear after the message. - [[[OWSDisappearingConfigurationUpdateInfoMessage alloc] initWithTimestamp:message.timestamp + 1 + // We want the info message to appear _before_ the message. + [[[OWSDisappearingConfigurationUpdateInfoMessage alloc] initWithTimestamp:message.timestamp - 1 thread:message.thread configuration:disappearingMessagesConfiguration] save]; diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index 0d96a0fb7..bd8a47249 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -193,7 +193,7 @@ NS_ASSUME_NONNULL_BEGIN } else { // Desktop currently sends delivery receipts for "unpersisted" messages // like group updates, so these errors are expected to a certain extent. - DDLogError(@"%@ Unexpected message with timestamp: %llu", self.tag, envelope.timestamp); + DDLogInfo(@"%@ Unexpected message with timestamp: %llu", self.tag, envelope.timestamp); } } diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index c7e117710..d8c944cef 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -434,7 +434,13 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; // // That's key - we don't want to send any messages in response // to an incoming message until processing of that batch of messages - // is complete. + // is complete. For example, we wouldn't want to auto-reply to a + // group info request before that group info request's batch was + // finished processing. Otherwise, we might receive a delivery + // notice for a group update we hadn't yet saved to the db. + // + // So we're using YDB behavior to ensure this invariant, which is a bit + // unorthodox. [message updateWithMessageState:TSOutgoingMessageStateAttemptingOut]; OWSSendMessageOperation *sendMessageOperation = @@ -1328,14 +1334,12 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; // TODO: Why is this necessary? [message save]; } else if (message.groupMetaMessage == TSGroupMessageQuit) { - // We want the info message to appear after the message. - [[[TSInfoMessage alloc] initWithTimestamp:message.timestamp + 1 + [[[TSInfoMessage alloc] initWithTimestamp:message.timestamp inThread:thread messageType:TSInfoMessageTypeGroupQuit customMessage:message.customMessage] save]; } else { - // We want the info message to appear after the message. - [[[TSInfoMessage alloc] initWithTimestamp:message.timestamp + 1 + [[[TSInfoMessage alloc] initWithTimestamp:message.timestamp inThread:thread messageType:TSInfoMessageTypeGroupUpdate customMessage:message.customMessage] save];