|
|
@ -210,17 +210,7 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
|
|
|
|
|
|
|
|
|
|
|
|
self.isProcessing = YES;
|
|
|
|
self.isProcessing = YES;
|
|
|
|
|
|
|
|
|
|
|
|
// Process read receipts every N seconds.
|
|
|
|
[self process];
|
|
|
|
//
|
|
|
|
|
|
|
|
// We want a value high enough to allow us to effectively de-duplicate,
|
|
|
|
|
|
|
|
// read receipts without being so high that we risk not sending read
|
|
|
|
|
|
|
|
// receipts due to app exit.
|
|
|
|
|
|
|
|
const CGFloat kProcessingFrequencySeconds = 3.f;
|
|
|
|
|
|
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(kProcessingFrequencySeconds * NSEC_PER_SEC)),
|
|
|
|
|
|
|
|
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
|
|
|
|
|
|
|
|
^{
|
|
|
|
|
|
|
|
[self process];
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -231,9 +221,9 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
|
|
|
|
{
|
|
|
|
{
|
|
|
|
DDLogVerbose(@"%@ Processing read receipts.", self.tag);
|
|
|
|
DDLogVerbose(@"%@ Processing read receipts.", self.tag);
|
|
|
|
|
|
|
|
|
|
|
|
self.isProcessing = NO;
|
|
|
|
// OWSReadReceipt
|
|
|
|
|
|
|
|
NSArray<OWSLinkedDeviceReadReceipt *> *readReceiptsForLinkedDevices =
|
|
|
|
NSArray<OWSReadReceipt *> *readReceiptsForLinkedDevices = [self.toLinkedDevicesReadReceiptMap allValues];
|
|
|
|
[self.toLinkedDevicesReadReceiptMap allValues];
|
|
|
|
[self.toLinkedDevicesReadReceiptMap removeAllObjects];
|
|
|
|
[self.toLinkedDevicesReadReceiptMap removeAllObjects];
|
|
|
|
if (readReceiptsForLinkedDevices.count > 0) {
|
|
|
|
if (readReceiptsForLinkedDevices.count > 0) {
|
|
|
|
OWSReadReceiptsForLinkedDevicesMessage *message =
|
|
|
|
OWSReadReceiptsForLinkedDevicesMessage *message =
|
|
|
@ -250,11 +240,12 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NSArray<OWSReadReceipt *> *readReceiptsToSend = [self.toLinkedDevicesReadReceiptMap allValues];
|
|
|
|
NSDictionary<NSString *, NSMutableSet<NSNumber *> *> *toSenderReadReceiptMap =
|
|
|
|
[self.toLinkedDevicesReadReceiptMap removeAllObjects];
|
|
|
|
[self.toSenderReadReceiptMap copy];
|
|
|
|
if (self.toSenderReadReceiptMap.count > 0) {
|
|
|
|
[self.toSenderReadReceiptMap removeAllObjects];
|
|
|
|
for (NSString *recipientId in self.toSenderReadReceiptMap) {
|
|
|
|
if (toSenderReadReceiptMap.count > 0) {
|
|
|
|
NSSet<NSNumber *> *timestamps = self.toSenderReadReceiptMap[recipientId];
|
|
|
|
for (NSString *recipientId in toSenderReadReceiptMap) {
|
|
|
|
|
|
|
|
NSSet<NSNumber *> *timestamps = toSenderReadReceiptMap[recipientId];
|
|
|
|
OWSAssert(timestamps.count > 0);
|
|
|
|
OWSAssert(timestamps.count > 0);
|
|
|
|
|
|
|
|
|
|
|
|
TSThread *thread = [TSContactThread getOrCreateThreadWithContactId:recipientId];
|
|
|
|
TSThread *thread = [TSContactThread getOrCreateThreadWithContactId:recipientId];
|
|
|
@ -264,8 +255,7 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
|
|
|
|
|
|
|
|
|
|
|
|
[self.messageSender sendMessage:message
|
|
|
|
[self.messageSender sendMessage:message
|
|
|
|
success:^{
|
|
|
|
success:^{
|
|
|
|
DDLogInfo(
|
|
|
|
DDLogInfo(@"%@ Successfully sent %zd read receipts to sender.", self.tag, timestamps.count);
|
|
|
|
@"%@ Successfully sent %zd read receipts to sender.", self.tag, readReceiptsToSend.count);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
failure:^(NSError *error) {
|
|
|
|
failure:^(NSError *error) {
|
|
|
|
DDLogError(@"%@ Failed to send read receipts to sender with error: %@", self.tag, error);
|
|
|
|
DDLogError(@"%@ Failed to send read receipts to sender with error: %@", self.tag, error);
|
|
|
@ -273,6 +263,25 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[self.toSenderReadReceiptMap removeAllObjects];
|
|
|
|
[self.toSenderReadReceiptMap removeAllObjects];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BOOL didWork = (readReceiptsForLinkedDevices.count > 0 || toSenderReadReceiptMap.count > 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (didWork) {
|
|
|
|
|
|
|
|
// Wait N seconds before processing read receipts again.
|
|
|
|
|
|
|
|
// This allows time for a batch to accumulate.
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// We want a value high enough to allow us to effectively de-duplicate,
|
|
|
|
|
|
|
|
// read receipts without being so high that we risk not sending read
|
|
|
|
|
|
|
|
// receipts due to app exit.
|
|
|
|
|
|
|
|
const CGFloat kProcessingFrequencySeconds = 3.f;
|
|
|
|
|
|
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(kProcessingFrequencySeconds * NSEC_PER_SEC)),
|
|
|
|
|
|
|
|
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
|
|
|
|
|
|
|
|
^{
|
|
|
|
|
|
|
|
[self process];
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
self.isProcessing = NO;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|