Merge pull request #255 from loki-project/unread-indicator-bug

Patch Unread Indicator Bug
pull/256/head
Niels Andriesse 5 years ago committed by GitHub
commit 2f8acd0779
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3607,7 +3607,6 @@ typedef enum : NSUInteger {
// and won't update the UI state immediately. // and won't update the UI state immediately.
- (void)didScrollToBottom - (void)didScrollToBottom
{ {
id<ConversationViewItem> _Nullable lastVisibleViewItem = [self.viewItems lastObject]; id<ConversationViewItem> _Nullable lastVisibleViewItem = [self.viewItems lastObject];
if (lastVisibleViewItem) { if (lastVisibleViewItem) {
uint64_t lastVisibleSortId = lastVisibleViewItem.interaction.sortId; uint64_t lastVisibleSortId = lastVisibleViewItem.interaction.sortId;

@ -63,8 +63,16 @@ NS_ASSUME_NONNULL_BEGIN
interactionIndexMap[viewItem.interaction.uniqueId] = @(i); interactionIndexMap[viewItem.interaction.uniqueId] = @(i);
[interactionIds addObject:viewItem.interaction.uniqueId]; [interactionIds addObject:viewItem.interaction.uniqueId];
if (viewItem.unreadIndicator != nil) { if (viewItem.unreadIndicator != nil && [viewItem.interaction conformsToProtocol:@protocol(OWSReadTracking)]) {
_unreadIndicatorIndex = @(i); id<OWSReadTracking> interaction = (id<OWSReadTracking>)viewItem.interaction;
// Under normal circumstances !interaction.read should always evaluate to true at this point, but
// there is a bug that can somehow cause it to be false leading to conversations permanently being
// stuck with "unread" messages.
if (!interaction.read) {
_unreadIndicatorIndex = @(i);
}
} }
} }
_interactionIndexMap = [interactionIndexMap copy]; _interactionIndexMap = [interactionIndexMap copy];

@ -348,7 +348,12 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa
OWSFailDebug(@"Unexpected object in unseen messages: %@", [object class]); OWSFailDebug(@"Unexpected object in unseen messages: %@", [object class]);
return; return;
} }
[messages addObject:(id<OWSReadTracking>)object]; id<OWSReadTracking> unread = (id<OWSReadTracking>)object;
if (unread.read) {
[LKLogger print:@"Found an already read message in the * unseen * messages list."];
return;
}
[messages addObject:unread];
}]; }];
return [messages copy]; return [messages copy];
@ -356,7 +361,24 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa
- (NSUInteger)unreadMessageCountWithTransaction:(YapDatabaseReadTransaction *)transaction - (NSUInteger)unreadMessageCountWithTransaction:(YapDatabaseReadTransaction *)transaction
{ {
return [[transaction ext:TSUnreadDatabaseViewExtensionName] numberOfItemsInGroup:self.uniqueId]; __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)]) {
OWSFailDebug(@"Unexpected object in unread messages: %@", [object class]);
return;
}
id<OWSReadTracking> unread = (id<OWSReadTracking>)object;
if (unread.read) {
[LKLogger print:@"Found an already read message in the * unread * messages list."];
return;
}
count += 1;
}];
return count;
} }
- (void)markAllAsReadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction - (void)markAllAsReadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction

@ -18,6 +18,7 @@
#import "TSThread.h" #import "TSThread.h"
#import "UIImage+OWS.h" #import "UIImage+OWS.h"
#import <YapDatabase/YapDatabase.h> #import <YapDatabase/YapDatabase.h>
#import <SessionServiceKit/SessionServiceKit-Swift.h>
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@ -65,6 +66,30 @@ NS_ASSUME_NONNULL_BEGIN
- (NSUInteger)unreadMessagesCount - (NSUInteger)unreadMessagesCount
{ {
__block NSUInteger count = 0;
[LKStorage readWithBlock:^(YapDatabaseReadTransaction *transaction) {
YapDatabaseViewTransaction *unreadMessages = [transaction ext:TSUnreadDatabaseViewExtensionName];
NSArray<NSString *> *allGroups = [unreadMessages allGroups];
for (NSString *groupID in allGroups) {
[unreadMessages enumerateKeysAndObjectsInGroup:groupID
usingBlock:^(NSString *collection, NSString *key, id object, NSUInteger index, BOOL *stop) {
if (![object conformsToProtocol:@protocol(OWSReadTracking)]) {
OWSFailDebug(@"Unexpected object in unread messages: %@", [object class]);
return;
}
id<OWSReadTracking> unread = (id<OWSReadTracking>)object;
if (unread.read) {
[LKLogger print:@"Found an already read message in the * unread * messages list."];
return;
}
count += 1;
}];
}
}];
return count;
__block NSUInteger numberOfItems; __block NSUInteger numberOfItems;
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { [self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
numberOfItems = [[transaction ext:TSUnreadDatabaseViewExtensionName] numberOfItemsInAllGroups]; numberOfItems = [[transaction ext:TSUnreadDatabaseViewExtensionName] numberOfItemsInAllGroups];

@ -491,7 +491,10 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
return; return;
} }
OWSAssertDebug(!possiblyRead.read); // Under normal circumstances !possiblyRead.read should always evaluate to true at this point, but
// there is a bug that can somehow cause it to be false leading to conversations permanently being
// stuck with "unread" messages.
OWSAssertDebug(possiblyRead.expireStartedAt == 0); OWSAssertDebug(possiblyRead.expireStartedAt == 0);
if (!possiblyRead.read) { if (!possiblyRead.read) {
[newlyReadList addObject:possiblyRead]; [newlyReadList addObject:possiblyRead];

Loading…
Cancel
Save