diff --git a/SignalServiceKit/src/Messages/Interactions/TSOutgoingDeleteMessage.m b/SignalServiceKit/src/Messages/Interactions/TSOutgoingDeleteMessage.m index b2c4b975ca..fa4e89b4e7 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSOutgoingDeleteMessage.m +++ b/SignalServiceKit/src/Messages/Interactions/TSOutgoingDeleteMessage.m @@ -66,10 +66,12 @@ NS_ASSUME_NONNULL_BEGIN [super anyUpdateOutgoingMessageWithTransaction:transaction block:block]; // Some older outgoing delete messages didn't store the deleted message's unique id. + // We want to mirror our sending state onto the original message, so it shows up + // within the conversation. if (self.messageUniqueId) { TSOutgoingMessage *deletedMessage = [TSOutgoingMessage anyFetchOutgoingMessageWithUniqueId:self.messageUniqueId transaction:transaction]; - [deletedMessage anyUpdateOutgoingMessageWithTransaction:transaction block:block]; + [deletedMessage updateWithRecipientAddressStates:self.recipientAddressStates transaction:transaction]; } } diff --git a/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m b/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m index fc825d5627..13e61cb81e 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m +++ b/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m @@ -874,6 +874,12 @@ NSUInteger const TSOutgoingMessageSchemaVersion = 1; OWSAssertDebug(recipientAddress.isValid); OWSAssertDebug(transaction); + // Ignore receipts for messages that have been deleted. + // They are no longer relevant to this message. + if (self.wasRemotelyDeleted) { + return; + } + // If delivery notification doesn't include timestamp, use "now" as an estimate. if (!deliveryTimestamp) { deliveryTimestamp = @([NSDate ows_millisecondTimeStamp]); @@ -904,6 +910,12 @@ NSUInteger const TSOutgoingMessageSchemaVersion = 1; OWSAssertDebug(recipientAddress.isValid); OWSAssertDebug(transaction); + // Ignore receipts for messages that have been deleted. + // They are no longer relevant to this message. + if (self.wasRemotelyDeleted) { + return; + } + [self anyUpdateOutgoingMessageWithTransaction:transaction block:^(TSOutgoingMessage *message) { TSOutgoingMessageRecipientState *_Nullable recipientState diff --git a/SignalServiceKit/src/Messages/MessageSender.m b/SignalServiceKit/src/Messages/MessageSender.m index 3992b4da6e..bbeb3fea17 100644 --- a/SignalServiceKit/src/Messages/MessageSender.m +++ b/SignalServiceKit/src/Messages/MessageSender.m @@ -254,7 +254,11 @@ NSError *SSKEnsureError(NSError *_Nullable error, OWSErrorCode fallbackCode, NSS [self.databaseStorage readWithBlock:^(SDSAnyReadTransaction *transaction) { latestCopy = [TSInteraction anyFetchWithUniqueId:self.message.uniqueId transaction:transaction]; }]; - if (self.message.shouldBeSaved && latestCopy == nil) { + BOOL messageWasRemotelyDeleted = NO; + if ([latestCopy isKindOfClass:[TSOutgoingMessage class]]) { + messageWasRemotelyDeleted = ((TSOutgoingMessage *)latestCopy).wasRemotelyDeleted; + } + if ((self.message.shouldBeSaved && latestCopy == nil) || messageWasRemotelyDeleted) { OWSLogInfo(@"aborting message send; message deleted."); NSError *error = OWSErrorWithCodeDescription( OWSErrorCodeMessageDeletedBeforeSent, @"Message was deleted before it could be sent.");