refactor to apply this logic to unread message count
This commit is contained in:
parent
06958babcb
commit
48c74d9476
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<OWSReadTracking> unread = (id<OWSReadTracking>)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];
|
||||
}
|
||||
}
|
||||
}];
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue