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.
|
* @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;
|
- (void)markAllAsReadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction;
|
||||||
|
|
||||||
|
|
|
@ -290,19 +290,19 @@ BOOL IsNoteToSelfEnabled(void)
|
||||||
// return count;
|
// return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)hasUnreadMentionMessage
|
- (NSUInteger)unreadMentionMessageCount
|
||||||
{
|
{
|
||||||
__block BOOL hasUnreadMentionMessage;
|
__block NSUInteger unreadMentionMessageCount;
|
||||||
[[self dbReadConnection] readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
[[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];
|
YapDatabaseViewTransaction *unreadMentions = [transaction ext:TSUnreadMentionDatabaseViewExtensionName];
|
||||||
return [unreadMentions numberOfItemsInGroup:self.uniqueId] > 0;
|
return [unreadMentions numberOfItemsInGroup:self.uniqueId];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)markAllAsReadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
- (void)markAllAsReadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||||
|
|
|
@ -81,25 +81,12 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
BOOL isGroupThread = thread.isGroupThread;
|
BOOL isGroupThread = thread.isGroupThread;
|
||||||
|
|
||||||
[unreadMessages enumerateKeysAndObjectsInGroup:groupID
|
// For groups that only notifiy for mentions
|
||||||
usingBlock:^(NSString *collection, NSString *key, id object, NSUInteger index, BOOL *stop) {
|
if (isGroupThread && ((TSGroupThread *)thread).isOnlyNotifyingForMentions) {
|
||||||
if (![object conformsToProtocol:@protocol(OWSReadTracking)]) {
|
count += [thread unreadMentionMessageCountWithTransaction:transaction];
|
||||||
return;
|
} else {
|
||||||
}
|
count += [thread unreadMessageCountWithTransaction:transaction];
|
||||||
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;
|
|
||||||
}];
|
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class ThreadViewModel: NSObject {
|
||||||
|
|
||||||
self.unreadCount = thread.unreadMessageCount(transaction: transaction)
|
self.unreadCount = thread.unreadMessageCount(transaction: transaction)
|
||||||
self.hasUnreadMessages = unreadCount > 0
|
self.hasUnreadMessages = unreadCount > 0
|
||||||
self.hasUnreadMentions = thread.hasUnreadMentionMessage(with: transaction)
|
self.hasUnreadMentions = thread.unreadMentionMessageCount(with: transaction) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
|
|
Loading…
Reference in New Issue