diff --git a/SessionMessagingKit/Threads/TSThread.h b/SessionMessagingKit/Threads/TSThread.h index 723a85dec..9a925a177 100644 --- a/SessionMessagingKit/Threads/TSThread.h +++ b/SessionMessagingKit/Threads/TSThread.h @@ -74,9 +74,9 @@ BOOL IsNoteToSelfEnabled(void); /** * @return If there is any message mentioning current user in this thread. */ -- (BOOL)hasUnreadMentionMessage; +- (NSUInteger)unreadMentionMessageCount; -- (BOOL)hasUnreadMentionMessageWithTransaction:(YapDatabaseReadTransaction *)transaction; +- (NSUInteger)unreadMentionMessageCountWithTransaction:(YapDatabaseReadTransaction *)transaction; - (void)markAllAsReadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction; diff --git a/SessionMessagingKit/Threads/TSThread.m b/SessionMessagingKit/Threads/TSThread.m index 98b5986c5..3311f5705 100644 --- a/SessionMessagingKit/Threads/TSThread.m +++ b/SessionMessagingKit/Threads/TSThread.m @@ -290,19 +290,19 @@ BOOL IsNoteToSelfEnabled(void) // return count; } -- (BOOL)hasUnreadMentionMessage +- (NSUInteger)unreadMentionMessageCount { - __block BOOL hasUnreadMentionMessage; + __block NSUInteger unreadMentionMessageCount; [[self dbReadConnection] readWithBlock:^(YapDatabaseReadTransaction *transaction) { - hasUnreadMentionMessage = [self hasUnreadMentionMessageWithTransaction:transaction]; + unreadMentionMessageCount = [self unreadMentionMessageCountWithTransaction:transaction]; }]; - return hasUnreadMentionMessage; + return unreadMentionMessageCount; } -- (BOOL)hasUnreadMentionMessageWithTransaction:(YapDatabaseReadTransaction *)transaction +- (NSUInteger)unreadMentionMessageCountWithTransaction:(YapDatabaseReadTransaction *)transaction { YapDatabaseViewTransaction *unreadMentions = [transaction ext:TSUnreadMentionDatabaseViewExtensionName]; - return [unreadMentions numberOfItemsInGroup:self.uniqueId] > 0; + return [unreadMentions numberOfItemsInGroup:self.uniqueId]; } - (void)markAllAsReadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction diff --git a/SignalUtilitiesKit/Messaging/OWSMessageUtils.m b/SignalUtilitiesKit/Messaging/OWSMessageUtils.m index d0facfff8..cbc703c91 100644 --- a/SignalUtilitiesKit/Messaging/OWSMessageUtils.m +++ b/SignalUtilitiesKit/Messaging/OWSMessageUtils.m @@ -81,25 +81,12 @@ NS_ASSUME_NONNULL_BEGIN BOOL isGroupThread = thread.isGroupThread; - [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; - } - // 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) { - return; - } - } - count += 1; - }]; + // For groups that only notifiy for mentions + if (isGroupThread && ((TSGroupThread *)thread).isOnlyNotifyingForMentions) { + count += [thread unreadMentionMessageCountWithTransaction:transaction]; + } else { + count += [thread unreadMessageCountWithTransaction:transaction]; + } } }]; diff --git a/SignalUtilitiesKit/Messaging/ThreadViewModel.swift b/SignalUtilitiesKit/Messaging/ThreadViewModel.swift index 8a62c0f0d..12bcfd560 100644 --- a/SignalUtilitiesKit/Messaging/ThreadViewModel.swift +++ b/SignalUtilitiesKit/Messaging/ThreadViewModel.swift @@ -52,7 +52,7 @@ public class ThreadViewModel: NSObject { self.unreadCount = thread.unreadMessageCount(transaction: transaction) self.hasUnreadMessages = unreadCount > 0 - self.hasUnreadMentions = thread.hasUnreadMentionMessage(with: transaction) + self.hasUnreadMentions = thread.unreadMentionMessageCount(with: transaction) > 0 } @objc