Respond to CR.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent ffe44e68be
commit ee13084d5c

@ -85,7 +85,7 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe
[[NSNotificationCenter defaultCenter] addObserver:self [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleMessageRead:) selector:@selector(handleMessageRead:)
name:kMessageMarkedAsReadNotification name:kIncomingMessageMarkedAsReadNotification
object:nil]; object:nil];
return self; return self;

@ -13,8 +13,10 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithSenderId:(NSString *)senderId timestamp:(uint64_t)timestamp; - (instancetype)initWithSenderId:(NSString *)senderId timestamp:(uint64_t)timestamp;
+ (nullable OWSLinkedDeviceReadReceipt *)linkedDeviceReadReceiptWithSenderId:(NSString *)senderId + (nullable OWSLinkedDeviceReadReceipt *)findLinkedDeviceReadReceiptWithSenderId:(NSString *)senderId
timestamp:(uint64_t)timestamp; timestamp:(uint64_t)timestamp
transaction:
(YapDatabaseReadTransaction *)transaction;
@end @end

@ -27,13 +27,18 @@ NS_ASSUME_NONNULL_BEGIN
{ {
OWSAssert(senderId.length > 0 && timestamp > 0); OWSAssert(senderId.length > 0 && timestamp > 0);
return [NSString stringWithFormat:@"%@ %llu", senderId, timestamp]; return [NSString stringWithFormat:@"%@-%llu", senderId, timestamp];
} }
+ (nullable OWSLinkedDeviceReadReceipt *)linkedDeviceReadReceiptWithSenderId:(NSString *)senderId + (nullable OWSLinkedDeviceReadReceipt *)findLinkedDeviceReadReceiptWithSenderId:(NSString *)senderId
timestamp:(uint64_t)timestamp timestamp:(uint64_t)timestamp
transaction:
(YapDatabaseReadTransaction *)transaction
{ {
return [OWSLinkedDeviceReadReceipt fetchObjectWithUniqueID:[self uniqueIdForSenderId:senderId timestamp:timestamp]]; OWSAssert(transaction);
return [OWSLinkedDeviceReadReceipt fetchObjectWithUniqueID:[self uniqueIdForSenderId:senderId timestamp:timestamp]
transaction:transaction];
} }
#pragma mark - Logging #pragma mark - Logging

@ -113,7 +113,8 @@ NS_ASSUME_NONNULL_BEGIN
sentAt:transcript.expirationStartedAt sentAt:transcript.expirationStartedAt
transaction:transaction]; transaction:transaction];
[self.readReceiptManager updateOutgoingMessageFromLinkedDevice:outgoingMessage transaction:transaction]; [self.readReceiptManager applyEarlyReadReceiptsForOutgoingMessageFromLinkedDevice:outgoingMessage
transaction:transaction];
[attachmentsProcessor [attachmentsProcessor
fetchAttachmentsForMessage:outgoingMessage fetchAttachmentsForMessage:outgoingMessage

@ -898,7 +898,7 @@ NS_ASSUME_NONNULL_BEGIN
if (thread && incomingMessage) { if (thread && incomingMessage) {
// In case we already have a read receipt for this new message (this happens sometimes). // In case we already have a read receipt for this new message (this happens sometimes).
[OWSReadReceiptManager.sharedManager updateIncomingMessage:incomingMessage [OWSReadReceiptManager.sharedManager applyEarlyReadReceiptsForIncomingMessage:incomingMessage
transaction:transaction]; transaction:transaction];
// TODO: Do this synchronously. // TODO: Do this synchronously.

@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN
@class TSThread; @class TSThread;
@class YapDatabaseReadWriteTransaction; @class YapDatabaseReadWriteTransaction;
extern NSString *const kMessageMarkedAsReadNotification; extern NSString *const kIncomingMessageMarkedAsReadNotification;
// There are four kinds of read receipts: // There are four kinds of read receipts:
// //
@ -44,7 +44,7 @@ extern NSString *const kMessageMarkedAsReadNotification;
- (void)processReadReceiptsFromRecipient:(OWSSignalServiceProtosReceiptMessage *)receiptMessage - (void)processReadReceiptsFromRecipient:(OWSSignalServiceProtosReceiptMessage *)receiptMessage
envelope:(OWSSignalServiceProtosEnvelope *)envelope; envelope:(OWSSignalServiceProtosEnvelope *)envelope;
- (void)updateOutgoingMessageFromLinkedDevice:(TSOutgoingMessage *)message - (void)applyEarlyReadReceiptsForOutgoingMessageFromLinkedDevice:(TSOutgoingMessage *)message
transaction:(YapDatabaseReadWriteTransaction *)transaction; transaction:(YapDatabaseReadWriteTransaction *)transaction;
#pragma mark - Linked Device Read Receipts #pragma mark - Linked Device Read Receipts
@ -52,7 +52,7 @@ extern NSString *const kMessageMarkedAsReadNotification;
- (void)processReadReceiptsFromLinkedDevice:(NSArray<OWSSignalServiceProtosSyncMessageRead *> *)readReceiptProtos - (void)processReadReceiptsFromLinkedDevice:(NSArray<OWSSignalServiceProtosSyncMessageRead *> *)readReceiptProtos
transaction:(YapDatabaseReadWriteTransaction *)transaction; transaction:(YapDatabaseReadWriteTransaction *)transaction;
- (void)updateIncomingMessage:(TSIncomingMessage *)message - (void)applyEarlyReadReceiptsForIncomingMessage:(TSIncomingMessage *)message
transaction:(YapDatabaseReadWriteTransaction *)transaction; transaction:(YapDatabaseReadWriteTransaction *)transaction;
#pragma mark - Locally Read #pragma mark - Locally Read

@ -18,7 +18,7 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
NSString *const kMessageMarkedAsReadNotification = @"kMessageMarkedAsReadNotification"; NSString *const kIncomingMessageMarkedAsReadNotification = @"kIncomingMessageMarkedAsReadNotification";
@interface TSRecipientReadReceipt : TSYapDatabaseObject @interface TSRecipientReadReceipt : TSYapDatabaseObject
@ -315,8 +315,8 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
OWSLinkedDeviceReadReceipt *_Nullable oldReadReceipt = self.toLinkedDevicesReadReceiptMap[threadUniqueId]; OWSLinkedDeviceReadReceipt *_Nullable oldReadReceipt = self.toLinkedDevicesReadReceiptMap[threadUniqueId];
if (oldReadReceipt && oldReadReceipt.timestamp > newReadReceipt.timestamp) { if (oldReadReceipt && oldReadReceipt.timestamp > newReadReceipt.timestamp) {
// If there's an existing read receipt for the same thread with // If there's an existing "linked device" read receipt for the same thread with
// a newer timestamp, discard the new read receipt. // a newer timestamp, discard this "linked device" read receipt.
DDLogVerbose(@"%@ Ignoring redundant read receipt for linked devices.", self.tag); DDLogVerbose(@"%@ Ignoring redundant read receipt for linked devices.", self.tag);
} else { } else {
DDLogVerbose(@"%@ Enqueuing read receipt for linked devices.", self.tag); DDLogVerbose(@"%@ Enqueuing read receipt for linked devices.", self.tag);
@ -389,7 +389,7 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
}); });
} }
- (void)updateOutgoingMessageFromLinkedDevice:(TSOutgoingMessage *)message - (void)applyEarlyReadReceiptsForOutgoingMessageFromLinkedDevice:(TSOutgoingMessage *)message
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
OWSAssert(message); OWSAssert(message);
@ -414,7 +414,7 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
#pragma mark - Linked Device Read Receipts #pragma mark - Linked Device Read Receipts
- (void)updateIncomingMessage:(TSIncomingMessage *)message - (void)applyEarlyReadReceiptsForIncomingMessage:(TSIncomingMessage *)message
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
OWSAssert(message); OWSAssert(message);
@ -427,19 +427,18 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
return; return;
} }
OWSLinkedDeviceReadReceipt *_Nullable readReceipt = [OWSLinkedDeviceReadReceipt linkedDeviceReadReceiptWithSenderId:senderId OWSLinkedDeviceReadReceipt *_Nullable readReceipt =
timestamp:timestamp]; [OWSLinkedDeviceReadReceipt findLinkedDeviceReadReceiptWithSenderId:senderId
timestamp:timestamp
transaction:transaction];
if (!readReceipt) { if (!readReceipt) {
return; return;
} }
[message markAsReadWithTransaction:transaction sendReadReceipt:NO updateExpiration:YES]; [message markAsReadWithTransaction:transaction sendReadReceipt:NO updateExpiration:YES];
[readReceipt removeWithTransaction:transaction]; [readReceipt removeWithTransaction:transaction];
dispatch_async(dispatch_get_main_queue(), ^{ [[NSNotificationCenter defaultCenter] postNotificationNameAsync:kIncomingMessageMarkedAsReadNotification
[[NSNotificationCenter defaultCenter]
postNotificationNameAsync:kMessageMarkedAsReadNotification
object:message]; object:message];
});
} }
- (void)processReadReceiptsFromLinkedDevice:(NSArray<OWSSignalServiceProtosSyncMessageRead *> *)readReceiptProtos - (void)processReadReceiptsFromLinkedDevice:(NSArray<OWSSignalServiceProtosSyncMessageRead *> *)readReceiptProtos
@ -545,11 +544,8 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
if ([possiblyRead isKindOfClass:[TSIncomingMessage class]]) { if ([possiblyRead isKindOfClass:[TSIncomingMessage class]]) {
TSIncomingMessage *incomingMessage = (TSIncomingMessage *)possiblyRead; TSIncomingMessage *incomingMessage = (TSIncomingMessage *)possiblyRead;
dispatch_async(dispatch_get_main_queue(), ^{ [[NSNotificationCenter defaultCenter] postNotificationNameAsync:kIncomingMessageMarkedAsReadNotification
[[NSNotificationCenter defaultCenter]
postNotificationNameAsync:kMessageMarkedAsReadNotification
object:incomingMessage]; object:incomingMessage];
});
} }
} }
} }

@ -442,12 +442,10 @@ NSString *const TSSecondaryDevicesDatabaseViewExtensionName = @"TSSecondaryDevic
asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) { asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
[TSDatabaseView.sharedInstance setAreAllAsyncRegistrationsComplete]; [TSDatabaseView.sharedInstance setAreAllAsyncRegistrationsComplete];
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
postNotificationNameAsync:kNSNotificationName_DatabaseViewRegistrationComplete postNotificationNameAsync:kNSNotificationName_DatabaseViewRegistrationComplete
object:nil object:nil
userInfo:nil]; userInfo:nil];
});
}]; }];
} }

Loading…
Cancel
Save