improve mention and unread message count

pull/541/head
Ryan Zhao 3 years ago
parent 16c9b7793a
commit 36907d3af0

@ -287,6 +287,10 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
for (id<OWSReadTracking> readItem in newlyReadList) {
[readItem markAsReadAtTimestamp:readTimestamp sendReadReceipt:wasLocal transaction:transaction];
}
// Update unread mention.
thread.hasUnreadMentionMessage = false;
[thread saveWithTransaction:transaction];
}
#pragma mark - Settings

@ -16,6 +16,7 @@ BOOL IsNoteToSelfEnabled(void);
*/
@interface TSThread : TSYapDatabaseObject
@property (nonatomic) BOOL hasUnreadMentionMessage;
@property (nonatomic) BOOL isPinned;
@property (nonatomic) BOOL shouldBeVisible;
@property (nonatomic, readonly) NSDate *creationDate;
@ -61,9 +62,6 @@ BOOL IsNoteToSelfEnabled(void);
- (NSUInteger)unreadMessageCountWithTransaction:(YapDatabaseReadTransaction *)transaction
NS_SWIFT_NAME(unreadMessageCount(transaction:));
- (BOOL)hasUnreadMentionMessageWithTransaction:(YapDatabaseReadTransaction *)transaction
NS_SWIFT_NAME(hasUnreadMentionMessage(transaction:));
- (void)markAllAsReadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction;
/**

@ -254,46 +254,22 @@ BOOL IsNoteToSelfEnabled(void)
__block NSUInteger count = 0;
YapDatabaseViewTransaction *unreadMessages = [transaction ext:TSUnreadDatabaseViewExtensionName];
[unreadMessages enumerateKeysAndObjectsInGroup:self.uniqueId
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;
}
count += 1;
}];
count = [unreadMessages numberOfItemsInGroup:self.uniqueId];
return count;
}
- (BOOL)hasUnreadMentionMessageWithTransaction:(YapDatabaseReadTransaction *)transaction
{
__block BOOL hasUnreadMention = false;
YapDatabaseViewTransaction *unreadMessages = [transaction ext:TSUnreadDatabaseViewExtensionName];
[unreadMessages enumerateKeysAndObjectsInGroup:self.uniqueId
usingBlock:^(NSString *collection, NSString *key, id object, NSUInteger index, BOOL *stop) {
if (![object isKindOfClass:[TSIncomingMessage class]]) {
return;
}
TSIncomingMessage* unreadMessage = (TSIncomingMessage*)object;
if (unreadMessage.read) {
NSLog(@"Found an already read message in the * unread * messages list.");
return;
}
if (unreadMessage.isUserMentioned) {
hasUnreadMention = true;
*stop = YES;
}
}];
return hasUnreadMention;
// FIXME: Why did we have to do as the following?
// [unreadMessages enumerateKeysAndObjectsInGroup:self.uniqueId
// 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;
// }
// count += 1;
// }];
}
- (void)markAllAsReadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
@ -301,6 +277,10 @@ BOOL IsNoteToSelfEnabled(void)
for (id<OWSReadTracking> message in [self unseenMessagesWithTransaction:transaction]) {
[message markAsReadAtTimestamp:[NSDate ows_millisecondTimeStamp] sendReadReceipt:YES transaction:transaction];
}
// Update unread mention.
self.hasUnreadMentionMessage = false;
[super saveWithTransaction:transaction];
}
- (nullable TSInteraction *)lastInteractionForInboxWithTransaction:(YapDatabaseReadTransaction *)transaction
@ -366,6 +346,12 @@ BOOL IsNoteToSelfEnabled(void)
_lastInteractionDate = lastMessage.receivedAtDate;
[super saveWithTransaction:transaction];
}
// Update unread mention if there is a new incoming message.
if ([lastMessage isKindOfClass:[TSIncomingMessage class]] && ((TSIncomingMessage *)lastMessage).isUserMentioned) {
self.hasUnreadMentionMessage = true;
[super saveWithTransaction:transaction];
}
if (!self.shouldBeVisible) {
self.shouldBeVisible = YES;

@ -52,7 +52,7 @@ public class ThreadViewModel: NSObject {
self.unreadCount = thread.unreadMessageCount(transaction: transaction)
self.hasUnreadMessages = unreadCount > 0
self.hasUnreadMentions = thread.hasUnreadMentionMessage(transaction: transaction)
self.hasUnreadMentions = thread.hasUnreadMentionMessage
}
@objc

Loading…
Cancel
Save