From 6a892c41504ec1c5ffdfee002c323fdb9f37eebe Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Sat, 15 Feb 2020 11:01:36 -0700 Subject: [PATCH] Partial Revert of 'Mark messages locally as read but wait to send receipts until the message request is approved.' Reverting all the OutgoingReceiptManager logic changes - but keeping some ancillary changes. --- .../ConversationViewController.m | 5 ++ SignalMessaging/profiles/OWSProfileManager.m | 17 ------- .../src/Messages/OWSOutgoingReceiptManager.h | 4 +- .../src/Messages/OWSOutgoingReceiptManager.m | 34 +------------ .../Database/Records/InteractionFinder.swift | 51 +------------------ 5 files changed, 9 insertions(+), 102 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 21f36f9696..7239aa9e01 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -3670,6 +3670,11 @@ typedef enum : NSUInteger { - (void)markVisibleMessagesAsRead { + // Don't mark messages as read until the message request has been processed + if (self.messageRequestView) { + return; + } + if (self.presentedViewController) { return; } diff --git a/SignalMessaging/profiles/OWSProfileManager.m b/SignalMessaging/profiles/OWSProfileManager.m index c0edd712d7..d2513773c1 100644 --- a/SignalMessaging/profiles/OWSProfileManager.m +++ b/SignalMessaging/profiles/OWSProfileManager.m @@ -171,11 +171,6 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640; return SSKEnvironment.shared.syncManager; } -- (OWSOutgoingReceiptManager *)outgoingReceiptManager -{ - return SSKEnvironment.shared.outgoingReceiptManager; -} - - (id)udManager { OWSAssertDebug(SSKEnvironment.shared.udManager); @@ -961,9 +956,6 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640; [OWSStorageServiceManager.shared recordPendingUpdatesWithUpdatedAddresses:addressesToRemove.allObjects]; } - // If we've updated our whitelist, there may be new read receipts ready to process. - [self.outgoingReceiptManager process]; - for (SignalServiceAddress *address in addressesToRemove) { [[NSNotificationCenter defaultCenter] postNotificationNameAsync:kNSNotificationName_ProfileWhitelistDidChange @@ -1000,9 +992,6 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640; [OWSStorageServiceManager.shared recordPendingUpdatesWithUpdatedAddresses:addressesToAdd.allObjects]; } - // If we've updated our whitelist, there may be new read receipts ready to process. - [self.outgoingReceiptManager process]; - for (SignalServiceAddress *address in addressesToAdd) { [[NSNotificationCenter defaultCenter] postNotificationNameAsync:kNSNotificationName_ProfileWhitelistDidChange @@ -1117,9 +1106,6 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640; [OWSStorageServiceManager.shared recordPendingUpdatesWithUpdatedGroupIds:@[ groupId ]]; } - // If we've updated our whitelist, there may be new read receipts ready to process. - [self.outgoingReceiptManager process]; - [[NSNotificationCenter defaultCenter] postNotificationNameAsync:kNSNotificationName_ProfileWhitelistDidChange object:nil userInfo:@ { @@ -1144,9 +1130,6 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640; [OWSStorageServiceManager.shared recordPendingUpdatesWithUpdatedGroupIds:@[ groupId ]]; } - // If we've updated our whitelist, there may be new read receipts ready to process. - [self.outgoingReceiptManager process]; - [[NSNotificationCenter defaultCenter] postNotificationNameAsync:kNSNotificationName_ProfileWhitelistDidChange object:nil userInfo:@ { diff --git a/SignalServiceKit/src/Messages/OWSOutgoingReceiptManager.h b/SignalServiceKit/src/Messages/OWSOutgoingReceiptManager.h index 026187a919..77d03c3d9c 100644 --- a/SignalServiceKit/src/Messages/OWSOutgoingReceiptManager.h +++ b/SignalServiceKit/src/Messages/OWSOutgoingReceiptManager.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2020 Open Whisper Systems. All rights reserved. +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. // NS_ASSUME_NONNULL_BEGIN @@ -18,8 +18,6 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)init NS_DESIGNATED_INITIALIZER; -- (void)process; - - (void)enqueueDeliveryReceiptForEnvelope:(SSKProtoEnvelope *)envelope transaction:(SDSAnyWriteTransaction *)transaction; diff --git a/SignalServiceKit/src/Messages/OWSOutgoingReceiptManager.m b/SignalServiceKit/src/Messages/OWSOutgoingReceiptManager.m index 08e6da3401..1d5c7d0451 100644 --- a/SignalServiceKit/src/Messages/OWSOutgoingReceiptManager.m +++ b/SignalServiceKit/src/Messages/OWSOutgoingReceiptManager.m @@ -184,38 +184,8 @@ typedef NS_ENUM(NSUInteger, OWSReceiptType) { [store enumerateKeysAndObjectsWithTransaction:transaction block:^(NSString *key, id object, BOOL *stop) { NSString *recipientId = key; - NSMutableSet *timestamps = [object mutableCopy]; - - // Filter the pending receipts to remove any for threads that have a - // pending message request. We wait to send read receipts until a - // message request is approved. - if (receiptType == OWSReceiptType_Read && RemoteConfig.messageRequests) { - SignalServiceAddress *address = - [self addressForIdentifier:recipientId]; - if (!address.isValid) { - OWSFailDebug(@"Unexpected identifier."); - return; - } - - for (NSNumber *timestamp in [timestamps copy]) { - TSThread *_Nullable messageThread = [InteractionFinder - findThreadForInteractionWithTimestamp: - [timestamp unsignedLongLongValue] - author:address - transaction:transaction]; - - if (messageThread && - [AnyThreadFinder - hasPendingMessageRequestWithThread:messageThread - transaction:transaction]) { - [timestamps removeObject:timestamp]; - } - } - } - - if (timestamps.count > 0) { - queuedReceiptMap[recipientId] = [timestamps copy]; - } + NSSet *timestamps = object; + queuedReceiptMap[recipientId] = [timestamps copy]; }]; }]; diff --git a/SignalServiceKit/src/Storage/Database/Records/InteractionFinder.swift b/SignalServiceKit/src/Storage/Database/Records/InteractionFinder.swift index f7c7be04ca..4b4e23b374 100644 --- a/SignalServiceKit/src/Storage/Database/Records/InteractionFinder.swift +++ b/SignalServiceKit/src/Storage/Database/Records/InteractionFinder.swift @@ -1,5 +1,5 @@ // -// Copyright (c) 2020 Open Whisper Systems. All rights reserved. +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. // import Foundation @@ -228,55 +228,6 @@ public class InteractionFinder: NSObject, InteractionFinderAdapter { return nil } - @objc - public class func findThread( - forInteractionWithTimestamp timestamp: UInt64, - author: SignalServiceAddress, - transaction: SDSAnyReadTransaction - ) -> TSThread? { - guard timestamp > 0 else { - owsFailDebug("invalid timestamp: \(timestamp)") - return nil - } - - guard author.isValid else { - owsFailDebug("Invalid author \(author)") - return nil - } - - let interactions: [TSInteraction] - - do { - interactions = try InteractionFinder.interactions( - withTimestamp: timestamp, - filter: { $0 is TSMessage }, - transaction: transaction - ) - } catch { - owsFailDebug("Error loading interactions \(error.localizedDescription)") - return nil - } - - for interaction in interactions { - guard let message = interaction as? TSMessage else { - owsFailDebug("received unexpected non-message interaction") - continue - } - - if let incomingMessage = message as? TSIncomingMessage, - incomingMessage.authorAddress.isEqualToAddress(author) { - return incomingMessage.thread(transaction: transaction) - } - - if let outgoingMessage = message as? TSOutgoingMessage, - author.isLocalAddress { - return outgoingMessage.thread(transaction: transaction) - } - } - - return nil - } - // MARK: - instance methods @objc