plumb through thread to read receipt manager

This commit is contained in:
Michael Kirk 2020-02-15 15:07:35 -07:00
parent f406de7797
commit 7efbeba2ef
9 changed files with 35 additions and 4 deletions

View File

@ -365,6 +365,7 @@ ConversationColorName const ConversationColorNameDefault = ConversationColorName
? OWSReadCircumstanceReadOnThisDeviceWhilePendingMessageRequest
: OWSReadCircumstanceReadOnThisDevice;
[message markAsReadAtTimestamp:[NSDate ows_millisecondTimeStamp]
thread:self
circumstance:circumstance
transaction:transaction];
}

View File

@ -311,6 +311,7 @@ NSUInteger TSErrorMessageSchemaVersion = 2;
}
- (void)markAsReadAtTimestamp:(uint64_t)readTimestamp
thread:(TSThread *)thread
circumstance:(OWSReadCircumstance)circumstance
transaction:(SDSAnyWriteTransaction *)transaction
{

View File

@ -194,11 +194,13 @@ const NSUInteger TSIncomingMessageSchemaVersion = 1;
// We want to do this without triggering sending read receipts, so we pretend it was
// read on a linked device.
[self markAsReadAtTimestamp:[NSDate ows_millisecondTimeStamp]
thread:[self threadWithTransaction:transaction]
circumstance:OWSReadCircumstanceReadOnLinkedDevice
transaction:transaction];
}
- (void)markAsReadAtTimestamp:(uint64_t)readTimestamp
thread:(TSThread *)thread
circumstance:(OWSReadCircumstance)circumstance
transaction:(SDSAnyWriteTransaction *)transaction
{
@ -224,7 +226,10 @@ const NSUInteger TSIncomingMessageSchemaVersion = 1;
expirationStartedAt:readTimestamp
transaction:transaction];
[OWSReadReceiptManager.sharedManager messageWasRead:self circumstance:circumstance transaction:transaction];
[OWSReadReceiptManager.sharedManager messageWasRead:self
thread:thread
circumstance:circumstance
transaction:transaction];
[transaction addAsyncCompletion:^{
[[NSNotificationCenter defaultCenter] postNotificationNameAsync:kIncomingMessageMarkedAsReadNotification

View File

@ -315,6 +315,7 @@ NSUInteger TSInfoMessageSchemaVersion = 2;
}
- (void)markAsReadAtTimestamp:(uint64_t)readTimestamp
thread:(TSThread *)thread
circumstance:(OWSReadCircumstance)circumstance
transaction:(SDSAnyWriteTransaction *)transaction
{

View File

@ -1786,6 +1786,7 @@ NS_ASSUME_NONNULL_BEGIN
OWSFailDebug(@"Incoming messages from yourself are not supported.");
// Don't send a read receipt for messages sent by ourselves.
[incomingMessage markAsReadAtTimestamp:envelope.timestamp
thread:thread
circumstance:OWSReadCircumstanceReadOnLinkedDevice
transaction:transaction];
}
@ -1840,6 +1841,7 @@ NS_ASSUME_NONNULL_BEGIN
// In case we already have a read receipt for this new message (this happens sometimes).
[OWSReadReceiptManager.sharedManager applyEarlyReadReceiptsForIncomingMessage:incomingMessage
thread:thread
transaction:transaction];
// TODO: Is this still necessary?

View File

@ -93,12 +93,14 @@ NS_SWIFT_NAME(init(grdbId:uniqueId:recipientMap:sentTimestamp:));
transaction:(SDSAnyWriteTransaction *)transaction;
- (void)applyEarlyReadReceiptsForIncomingMessage:(TSIncomingMessage *)message
thread:(TSThread *)thread
transaction:(SDSAnyWriteTransaction *)transaction;
#pragma mark - Locally Read
// This method can be called from any thread.
- (void)messageWasRead:(TSIncomingMessage *)message
thread:(TSThread *)thread
circumstance:(OWSReadCircumstance)circumstance
transaction:(SDSAnyWriteTransaction *)transaction;

View File

@ -359,6 +359,7 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
? OWSReadCircumstanceReadOnThisDeviceWhilePendingMessageRequest
: OWSReadCircumstanceReadOnThisDevice;
[self markMessagesAsRead:unreadMessages
thread:thread
readTimestamp:readTimestamp
circumstance:circumstance
transaction:transaction];
@ -368,6 +369,7 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
}
- (void)messageWasRead:(TSIncomingMessage *)message
thread:(TSThread *)thread
circumstance:(OWSReadCircumstance)circumstance
transaction:(SDSAnyWriteTransaction *)transaction;
{
@ -505,6 +507,7 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
#pragma mark - Linked Device Read Receipts
- (void)applyEarlyReadReceiptsForIncomingMessage:(TSIncomingMessage *)message
thread:(TSThread *)thread
transaction:(SDSAnyWriteTransaction *)transaction
{
OWSAssertDebug(message);
@ -526,6 +529,7 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
}
[message markAsReadAtTimestamp:readReceipt.readTimestamp
thread:thread
circumstance:OWSReadCircumstanceReadOnLinkedDevice
transaction:transaction];
[readReceipt anyRemoveWithTransaction:transaction];
@ -567,10 +571,18 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
if (messages.count > 0) {
for (TSIncomingMessage *message in messages) {
TSThread *_Nullable thread = [message threadWithTransaction:transaction];
if (thread == nil) {
OWSFailDebug(@"thread was unexpectedly nil");
continue;
}
NSTimeInterval secondsSinceRead = [NSDate new].timeIntervalSince1970 - readTimestamp / 1000;
OWSAssertDebug([message isKindOfClass:[TSIncomingMessage class]]);
OWSLogDebug(@"read on linked device %f seconds ago", secondsSinceRead);
[self markAsReadOnLinkedDevice:message readTimestamp:readTimestamp transaction:transaction];
[self markAsReadOnLinkedDevice:message
thread:thread
readTimestamp:readTimestamp
transaction:transaction];
}
} else {
// Received read receipt for unknown incoming message.
@ -585,20 +597,23 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
}
- (void)markAsReadOnLinkedDevice:(TSIncomingMessage *)message
thread:(TSThread *)thread
readTimestamp:(uint64_t)readTimestamp
transaction:(SDSAnyWriteTransaction *)transaction
{
OWSAssertDebug(message);
OWSAssertDebug(thread);
OWSAssertDebug(transaction);
// Always re-mark the message as read to ensure any earlier read time is applied to disappearing messages.
[message markAsReadAtTimestamp:readTimestamp
thread:thread
circumstance:OWSReadCircumstanceReadOnLinkedDevice
transaction:transaction];
// Also mark any unread messages appearing earlier in the thread as read as well.
[self markAsReadBeforeSortId:message.sortId
thread:[message threadWithTransaction:transaction]
thread:thread
readTimestamp:readTimestamp
circumstance:OWSReadCircumstanceReadOnLinkedDevice
transaction:transaction];
@ -623,12 +638,14 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
return;
}
[self markMessagesAsRead:unreadMessages
thread:thread
readTimestamp:readTimestamp
circumstance:circumstance
transaction:transaction];
}
- (void)markMessagesAsRead:(NSArray<id<OWSReadTracking>> *)unreadMessages
thread:(TSThread *)thread
readTimestamp:(uint64_t)readTimestamp
circumstance:(OWSReadCircumstance)circumstance
transaction:(SDSAnyWriteTransaction *)transaction
@ -649,7 +666,7 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
break;
}
for (id<OWSReadTracking> readItem in unreadMessages) {
[readItem markAsReadAtTimestamp:readTimestamp circumstance:circumstance transaction:transaction];
[readItem markAsReadAtTimestamp:readTimestamp thread:thread circumstance:circumstance transaction:transaction];
}
}

View File

@ -30,6 +30,7 @@ NS_ASSUME_NONNULL_BEGIN
* Used both for *responding* to a remote read receipt and in response to the local user's activity.
*/
- (void)markAsReadAtTimestamp:(uint64_t)readTimestamp
thread:(TSThread *)thread
circumstance:(OWSReadCircumstance)circumstance
transaction:(SDSAnyWriteTransaction *)transaction;

View File

@ -167,6 +167,7 @@ NSUInteger TSCallCurrentSchemaVersion = 1;
}
- (void)markAsReadAtTimestamp:(uint64_t)readTimestamp
thread:(TSThread *)thread
circumstance:(OWSReadCircumstance)circumstance
transaction:(SDSAnyWriteTransaction *)transaction
{