|
|
@ -254,46 +254,22 @@ BOOL IsNoteToSelfEnabled(void)
|
|
|
|
__block NSUInteger count = 0;
|
|
|
|
__block NSUInteger count = 0;
|
|
|
|
|
|
|
|
|
|
|
|
YapDatabaseViewTransaction *unreadMessages = [transaction ext:TSUnreadDatabaseViewExtensionName];
|
|
|
|
YapDatabaseViewTransaction *unreadMessages = [transaction ext:TSUnreadDatabaseViewExtensionName];
|
|
|
|
[unreadMessages enumerateKeysAndObjectsInGroup:self.uniqueId
|
|
|
|
count = [unreadMessages numberOfItemsInGroup: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;
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return count;
|
|
|
|
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
|
|
|
|
- (void)markAllAsReadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
|
|
@ -301,6 +277,10 @@ BOOL IsNoteToSelfEnabled(void)
|
|
|
|
for (id<OWSReadTracking> message in [self unseenMessagesWithTransaction:transaction]) {
|
|
|
|
for (id<OWSReadTracking> message in [self unseenMessagesWithTransaction:transaction]) {
|
|
|
|
[message markAsReadAtTimestamp:[NSDate ows_millisecondTimeStamp] sendReadReceipt:YES transaction:transaction];
|
|
|
|
[message markAsReadAtTimestamp:[NSDate ows_millisecondTimeStamp] sendReadReceipt:YES transaction:transaction];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update unread mention.
|
|
|
|
|
|
|
|
self.hasUnreadMentionMessage = false;
|
|
|
|
|
|
|
|
[super saveWithTransaction:transaction];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (nullable TSInteraction *)lastInteractionForInboxWithTransaction:(YapDatabaseReadTransaction *)transaction
|
|
|
|
- (nullable TSInteraction *)lastInteractionForInboxWithTransaction:(YapDatabaseReadTransaction *)transaction
|
|
|
@ -366,6 +346,12 @@ BOOL IsNoteToSelfEnabled(void)
|
|
|
|
_lastInteractionDate = lastMessage.receivedAtDate;
|
|
|
|
_lastInteractionDate = lastMessage.receivedAtDate;
|
|
|
|
[super saveWithTransaction:transaction];
|
|
|
|
[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) {
|
|
|
|
if (!self.shouldBeVisible) {
|
|
|
|
self.shouldBeVisible = YES;
|
|
|
|
self.shouldBeVisible = YES;
|
|
|
|