diff --git a/SignalServiceKit/src/Devices/OWSRecordTranscriptJob.m b/SignalServiceKit/src/Devices/OWSRecordTranscriptJob.m index 58ac8127d..a376dce94 100644 --- a/SignalServiceKit/src/Devices/OWSRecordTranscriptJob.m +++ b/SignalServiceKit/src/Devices/OWSRecordTranscriptJob.m @@ -146,7 +146,9 @@ NS_ASSUME_NONNULL_BEGIN } [outgoingMessage saveWithTransaction:transaction]; - [outgoingMessage updateWithWasSentFromLinkedDeviceWithTransaction:transaction]; + [outgoingMessage updateWithWasSentFromLinkedDeviceWithUDRecipientIds:transcript.udRecipientIds + nonUdRecipientIds:transcript.nonUdRecipientIds + transaction:transaction]; [[OWSDisappearingMessagesJob sharedJob] becomeConsistentWithConfigurationForMessage:outgoingMessage contactsManager:self.contactsManager transaction:transaction]; diff --git a/SignalServiceKit/src/Messages/DeviceSyncing/OWSIncomingSentMessageTranscript.h b/SignalServiceKit/src/Messages/DeviceSyncing/OWSIncomingSentMessageTranscript.h index 4a7ad6175..1d5573807 100644 --- a/SignalServiceKit/src/Messages/DeviceSyncing/OWSIncomingSentMessageTranscript.h +++ b/SignalServiceKit/src/Messages/DeviceSyncing/OWSIncomingSentMessageTranscript.h @@ -36,6 +36,11 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly, nullable) TSQuotedMessage *quotedMessage; @property (nonatomic, readonly, nullable) OWSContact *contact; +// If either nonUdRecipientIds or udRecipientIds is nil, +// this is either a legacy transcript or it reflects a legacy sync message. +@property (nonatomic, readonly, nullable) NSArray *nonUdRecipientIds; +@property (nonatomic, readonly, nullable) NSArray *udRecipientIds; + @end NS_ASSUME_NONNULL_END diff --git a/SignalServiceKit/src/Messages/DeviceSyncing/OWSIncomingSentMessageTranscript.m b/SignalServiceKit/src/Messages/DeviceSyncing/OWSIncomingSentMessageTranscript.m index b129fad3a..87084e78b 100644 --- a/SignalServiceKit/src/Messages/DeviceSyncing/OWSIncomingSentMessageTranscript.m +++ b/SignalServiceKit/src/Messages/DeviceSyncing/OWSIncomingSentMessageTranscript.m @@ -46,6 +46,29 @@ NS_ASSUME_NONNULL_BEGIN _quotedMessage = [TSQuotedMessage quotedMessageForDataMessage:_dataMessage thread:_thread transaction:transaction]; _contact = [OWSContacts contactForDataMessage:_dataMessage transaction:transaction]; + if (sentProto.unidentifiedStatus.count > 0) { + NSMutableArray *nonUdRecipientIds = [NSMutableArray new]; + NSMutableArray *udRecipientIds = [NSMutableArray new]; + for (SSKProtoSyncMessageSentUnidentifiedDeliveryStatus *statusProto in sentProto.unidentifiedStatus) { + if (!statusProto.hasDestination || statusProto.destination.length < 1) { + OWSFailDebug(@"Delivery status proto is missing destination."); + continue; + } + if (!statusProto.hasUnidentified) { + OWSFailDebug(@"Delivery status proto is missing value."); + continue; + } + NSString *recipientId = statusProto.destination; + if (statusProto.unidentified) { + [udRecipientIds addObject:recipientId]; + } else { + [nonUdRecipientIds addObject:recipientId]; + } + } + _nonUdRecipientIds = [nonUdRecipientIds copy]; + _udRecipientIds = [udRecipientIds copy]; + } + return self; } diff --git a/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.h b/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.h index 43de963d3..7c73bf122 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.h +++ b/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.h @@ -206,7 +206,9 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) { deliveryTimestamp:(NSNumber *_Nullable)deliveryTimestamp transaction:(YapDatabaseReadWriteTransaction *)transaction; -- (void)updateWithWasSentFromLinkedDeviceWithTransaction:(YapDatabaseReadWriteTransaction *)transaction; +- (void)updateWithWasSentFromLinkedDeviceWithUDRecipientIds:(nullable NSArray *)udRecipientIds + nonUdRecipientIds:(nullable NSArray *)nonUdRecipientIds + transaction:(YapDatabaseReadWriteTransaction *)transaction; // This method is used to rewrite the recipient list with a single recipient. // It is used to reply to a "group info request", which should only be diff --git a/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m b/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m index 8a992cba5..87e539561 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m +++ b/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m @@ -725,21 +725,45 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt }]; } -- (void)updateWithWasSentFromLinkedDeviceWithTransaction:(YapDatabaseReadWriteTransaction *)transaction -{ +- (void)updateWithWasSentFromLinkedDeviceWithUDRecipientIds:(nullable NSArray *)udRecipientIds + nonUdRecipientIds:(nullable NSArray *)nonUdRecipientIds + transaction:(YapDatabaseReadWriteTransaction *)transaction { OWSAssertDebug(transaction); - [self applyChangeToSelfAndLatestCopy:transaction - changeBlock:^(TSOutgoingMessage *message) { - // Mark any "sending" recipients as "sent." - for (TSOutgoingMessageRecipientState *recipientState in message.recipientStateMap - .allValues) { - if (recipientState.state == OWSOutgoingMessageRecipientStateSending) { - recipientState.state = OWSOutgoingMessageRecipientStateSent; - } - } - [message setIsFromLinkedDevice:YES]; - }]; + [self + applyChangeToSelfAndLatestCopy:transaction + changeBlock:^(TSOutgoingMessage *message) { + if (udRecipientIds.count > 0 || nonUdRecipientIds.count > 0) { + // If we have specific recipient info from the transcript, + // build a new recipient state map. + NSMutableDictionary *recipientStateMap + = [NSMutableDictionary new]; + for (NSString *recipientId in udRecipientIds) { + TSOutgoingMessageRecipientState *recipientState = + [TSOutgoingMessageRecipientState new]; + recipientState.state = OWSOutgoingMessageRecipientStateSent; + recipientState.wasSentByUD = YES; + recipientStateMap[recipientId] = recipientState; + } + for (NSString *recipientId in nonUdRecipientIds) { + TSOutgoingMessageRecipientState *recipientState = + [TSOutgoingMessageRecipientState new]; + recipientState.state = OWSOutgoingMessageRecipientStateSent; + recipientState.wasSentByUD = NO; + recipientStateMap[recipientId] = recipientState; + } + [message setRecipientStateMap:recipientStateMap]; + } else { + // Otherwise, mark any "sending" recipients as "sent." + for (TSOutgoingMessageRecipientState *recipientState in message.recipientStateMap + .allValues) { + if (recipientState.state == OWSOutgoingMessageRecipientStateSending) { + recipientState.state = OWSOutgoingMessageRecipientStateSent; + } + } + } + [message setIsFromLinkedDevice:YES]; + }]; } - (void)updateWithSendingToSingleGroupRecipient:(NSString *)singleGroupRecipient @@ -799,6 +823,7 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt } }]; } + #pragma mark - - (nullable SSKProtoDataMessageBuilder *)dataMessageBuilder