Handle new-style delivery receipts.

// FREEBIE
pull/1/head
Matthew Chen 7 years ago
parent 25c40ea3cf
commit aa7329013d

@ -293,8 +293,15 @@ class MessageMetadataViewController: OWSViewController {
MessageMetadataViewController.dateFormatter.string(from:readDate))
}
// TODO: We don't currently track delivery state on a per-recipient basis.
// We should. NOTE: This work is in PR.
let recipientDeliveryMap = message.recipientDeliveryMap
if let deliveryTimestamp = recipientDeliveryMap[recipientId] {
assert(message.messageState == .sentToService)
let deliveryDate = NSDate.ows_date(withMillisecondsSince1970:deliveryTimestamp.uint64Value)
return String(format:NSLocalizedString("MESSAGE_STATUS_DELIVERED_WITH_TIMESTAMP_FORMAT",
comment: "message status for messages delivered to the recipient. Embeds: {{the date and time the message was delivered}}."),
dateFormatter.string(from:deliveryDate))
}
if message.wasDelivered {
return NSLocalizedString("MESSAGE_STATUS_DELIVERED",
comment:"message status for message delivered to their recipient.")

@ -833,6 +833,9 @@
message status for message delivered to their recipient. */
"MESSAGE_STATUS_DELIVERED" = "Delivered";
/* message status for messages delivered to the recipient. Embeds: {{the date and time the message was delivered}}. */
"MESSAGE_STATUS_DELIVERED_WITH_TIMESTAMP_FORMAT" = "Delivered %@";
/* message footer for failed messages */
"MESSAGE_STATUS_FAILED" = "Sending failed. Tap for info.";

@ -104,6 +104,9 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
// This property won't be accurate for legacy messages.
@property (atomic, readonly) BOOL isFromLinkedDevice;
// Map of "recipient id"-to-"delivery time" of the recipients who have received the message.
@property (atomic, readonly) NSDictionary<NSString *, NSNumber *> *recipientDeliveryMap;
// Map of "recipient id"-to-"read time" of the recipients who have read the message.
@property (atomic, readonly) NSDictionary<NSString *, NSNumber *> *recipientReadMap;
@ -171,7 +174,10 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
- (void)updateWithHasSyncedTranscript:(BOOL)hasSyncedTranscript;
- (void)updateWithCustomMessage:(NSString *)customMessage transaction:(YapDatabaseReadWriteTransaction *)transaction;
- (void)updateWithCustomMessage:(NSString *)customMessage;
- (void)updateWithWasDeliveredWithTransaction:(YapDatabaseReadWriteTransaction *)transaction;
// deliveryTimestamp is an optional parameter.
- (void)updateWithDeliveredToRecipientId:(NSString *)recipientId
deliveryTimestamp:(NSNumber *_Nullable)deliveryTimestamp
transaction:(YapDatabaseReadWriteTransaction *)transaction;
- (void)updateWithWasSentFromLinkedDeviceWithTransaction:(YapDatabaseReadWriteTransaction *)transaction;
- (void)updateWithSingleGroupRecipient:(NSString *)singleGroupRecipient
transaction:(YapDatabaseReadWriteTransaction *)transaction;

@ -38,6 +38,8 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec
@property (atomic) TSGroupMetaMessage groupMetaMessage;
@property (atomic) NSDictionary<NSString *, NSNumber *> *recipientDeliveryMap;
@property (atomic) NSDictionary<NSString *, NSNumber *> *recipientReadMap;
@end
@ -307,12 +309,25 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec
}];
}
- (void)updateWithWasDeliveredWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
- (void)updateWithDeliveredToRecipientId:(NSString *)recipientId
deliveryTimestamp:(NSNumber *_Nullable)deliveryTimestamp
transaction:(YapDatabaseReadWriteTransaction *)transaction
{
OWSAssert(recipientId.length > 0);
OWSAssert(transaction);
[self applyChangeToSelfAndLatestOutgoingMessage:transaction
changeBlock:^(TSOutgoingMessage *message) {
if (deliveryTimestamp) {
NSMutableDictionary<NSString *, NSNumber *> *recipientDeliveryMap
= (message.recipientDeliveryMap
? [message.recipientDeliveryMap mutableCopy]
: [NSMutableDictionary new]);
recipientDeliveryMap[recipientId] = deliveryTimestamp;
message.recipientDeliveryMap = recipientDeliveryMap;
}
[message setWasDelivered:YES];
}];
}

@ -186,15 +186,19 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(envelope);
OWSAssert(transaction);
// Old-style delivery notices don't include a "delivery timestamp".
[self processDeliveryReceipts:envelope.source
sentTimestamps:@[
@(envelope.timestamp),
]
deliveryTimestamp:nil
transaction:transaction];
}
// deliveryTimestamp is an optional parameter.
- (void)processDeliveryReceipts:(NSString *)recipientId
sentTimestamps:(NSArray<NSNumber *> *)sentTimestamps
deliveryTimestamp:(NSNumber *_Nullable)deliveryTimestamp
transaction:(YapDatabaseReadWriteTransaction *)transaction
{
OWSAssert(recipientId);
@ -218,7 +222,9 @@ NS_ASSUME_NONNULL_BEGIN
@"%@ More than one message (%zd) for delivery receipt: %llu", self.tag, messages.count, timestamp);
}
for (TSOutgoingMessage *outgoingMessage in messages) {
[outgoingMessage updateWithWasDeliveredWithTransaction:transaction];
[outgoingMessage updateWithDeliveredToRecipientId:recipientId
deliveryTimestamp:deliveryTimestamp
transaction:transaction];
}
}
}
@ -373,7 +379,10 @@ NS_ASSUME_NONNULL_BEGIN
switch (receiptMessage.type) {
case OWSSignalServiceProtosReceiptMessageTypeDelivery:
DDLogVerbose(@"%@ Processing receipt message with delivery receipts.", self.tag);
[self processDeliveryReceipts:envelope.source sentTimestamps:sentTimestamps transaction:transaction];
[self processDeliveryReceipts:envelope.source
sentTimestamps:sentTimestamps
deliveryTimestamp:@(envelope.timestamp)
transaction:transaction];
return;
case OWSSignalServiceProtosReceiptMessageTypeRead:
DDLogVerbose(@"%@ Processing receipt message with read receipts.", self.tag);

Loading…
Cancel
Save