Apply UD status from transcripts.

pull/1/head
Matthew Chen 7 years ago
parent 0c6c506a36
commit 7e7fcc1698

@ -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];

@ -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<NSString *> *nonUdRecipientIds;
@property (nonatomic, readonly, nullable) NSArray<NSString *> *udRecipientIds;
@end
NS_ASSUME_NONNULL_END

@ -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<NSString *> *nonUdRecipientIds = [NSMutableArray new];
NSMutableArray<NSString *> *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;
}

@ -206,7 +206,9 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
deliveryTimestamp:(NSNumber *_Nullable)deliveryTimestamp
transaction:(YapDatabaseReadWriteTransaction *)transaction;
- (void)updateWithWasSentFromLinkedDeviceWithTransaction:(YapDatabaseReadWriteTransaction *)transaction;
- (void)updateWithWasSentFromLinkedDeviceWithUDRecipientIds:(nullable NSArray<NSString *> *)udRecipientIds
nonUdRecipientIds:(nullable NSArray<NSString *> *)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

@ -725,21 +725,45 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
}];
}
- (void)updateWithWasSentFromLinkedDeviceWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
{
- (void)updateWithWasSentFromLinkedDeviceWithUDRecipientIds:(nullable NSArray<NSString *> *)udRecipientIds
nonUdRecipientIds:(nullable NSArray<NSString *> *)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<NSString *, TSOutgoingMessageRecipientState *> *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

Loading…
Cancel
Save