From 3ab7192b261807f62a076654940ac42a5bc0ffcb Mon Sep 17 00:00:00 2001 From: Ryan Zhao Date: Wed, 2 Mar 2022 11:23:13 +1100 Subject: [PATCH] clean up some code related to unread message (requests) count --- .../Messaging/OWSMessageUtils.m | 23 +++---------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/SignalUtilitiesKit/Messaging/OWSMessageUtils.m b/SignalUtilitiesKit/Messaging/OWSMessageUtils.m index b07a80bf8..e50ac05ec 100644 --- a/SignalUtilitiesKit/Messaging/OWSMessageUtils.m +++ b/SignalUtilitiesKit/Messaging/OWSMessageUtils.m @@ -91,6 +91,7 @@ NS_ASSUME_NONNULL_BEGIN NSLog(@"Found an already read message in the * unread * messages list."); return; } + // We have to filter those unread messages for groups that only notifiy for mentions if ([object isKindOfClass:TSIncomingMessage.class] && isGroupThread) { TSIncomingMessage *incomingMessage = (TSIncomingMessage *)object; if (((TSGroupThread *)thread).isOnlyNotifyingForMentions && !incomingMessage.isUserMentioned) { @@ -103,13 +104,6 @@ NS_ASSUME_NONNULL_BEGIN }]; return count; - - __block NSUInteger numberOfItems; - [self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { - numberOfItems = [[transaction ext:TSUnreadDatabaseViewExtensionName] numberOfItemsInAllGroups]; - }]; - - return numberOfItems; } - (NSUInteger)unreadMessageRequestCount { @@ -124,20 +118,9 @@ NS_ASSUME_NONNULL_BEGIN // Only increase the count for message requests if (!thread.isMessageRequest) { continue; } - - [unreadMessages enumerateKeysAndObjectsInGroup:groupID - usingBlock:^(NSString *collection, NSString *key, id object, NSUInteger index, BOOL *stop) { - if (![object conformsToProtocol:@protocol(OWSReadTracking)]) { - return; - } - id unread = (id)object; - if (unread.read) { - NSLog(@"Found an already read message in the * unread * messages list."); - return; - } + if ([unreadMessages numberOfItemsInGroup:groupID] > 0) { count += 1; - *stop = YES; - }]; + } } }];