Process 'sent update' transcripts.

pull/2/head
Matthew Chen 6 years ago
parent ccc1bd3331
commit 6ce84e7f9b

@ -161,6 +161,7 @@ NS_ASSUME_NONNULL_BEGIN
[outgoingMessage saveWithTransaction:transaction];
[outgoingMessage updateWithWasSentFromLinkedDeviceWithUDRecipientIds:transcript.udRecipientIds
nonUdRecipientIds:transcript.nonUdRecipientIds
isSentUpdate:NO
transaction:transaction];
[[OWSDisappearingMessagesJob sharedJob] startAnyExpirationForMessage:outgoingMessage
expirationStartedAt:transcript.expirationStartedAt
@ -239,6 +240,13 @@ NS_ASSUME_NONNULL_BEGIN
BOOL messageFound = NO;
for (TSOutgoingMessage *message in messages) {
if (!message.isFromLinkedDevice) {
// isFromLinkedDevice isn't always set for very old linked messages, but:
//
// a) We should never receive a "sent update" for a very old message.
// b) It's safe to discard suspicious "sent updates."
continue;
}
TSThread *thread = [message threadWithTransaction:transaction];
if (!thread.isGroupThread) {
continue;
@ -257,6 +265,7 @@ NS_ASSUME_NONNULL_BEGIN
[message updateWithWasSentFromLinkedDeviceWithUDRecipientIds:udRecipientIds
nonUdRecipientIds:nonUdRecipientIds
isSentUpdate:YES
transaction:transaction];
messageFound = YES;
}

@ -220,6 +220,7 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
- (void)updateWithWasSentFromLinkedDeviceWithUDRecipientIds:(nullable NSArray<NSString *> *)udRecipientIds
nonUdRecipientIds:(nullable NSArray<NSString *> *)nonUdRecipientIds
isSentUpdate:(BOOL)isSentUpdate
transaction:(YapDatabaseReadWriteTransaction *)transaction;
// This method is used to rewrite the recipient list with a single recipient.

@ -753,7 +753,9 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
- (void)updateWithWasSentFromLinkedDeviceWithUDRecipientIds:(nullable NSArray<NSString *> *)udRecipientIds
nonUdRecipientIds:(nullable NSArray<NSString *> *)nonUdRecipientIds
transaction:(YapDatabaseReadWriteTransaction *)transaction {
isSentUpdate:(BOOL)isSentUpdate
transaction:(YapDatabaseReadWriteTransaction *)transaction
{
OWSAssertDebug(transaction);
[self
@ -788,6 +790,19 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
recipientState.wasSentByUD = NO;
recipientStateMap[recipientId] = recipientState;
}
if (isSentUpdate) {
// If this is a "sent update", make sure that:
//
// a) "Sent updates" should never remove any recipients. We end up with the
// union of the existing and new recipients.
// b) "Sent updates" should never downgrade the "recipient state" for any
// recipients. Prefer existing "recipient state"; "sent updates" only
// add new recipients at the "sent" state.
[recipientStateMap removeObjectsForKeys:self.recipientStateMap.allKeys];
[recipientStateMap addEntriesFromDictionary:self.recipientStateMap];
}
[message setRecipientStateMap:recipientStateMap];
} else {
// Otherwise assume this is a legacy message before UD was introduced, and mark

Loading…
Cancel
Save