Patch unread indicator bug
This commit is contained in:
parent
13d81edb8d
commit
4d13c6bee5
|
@ -3607,7 +3607,6 @@ typedef enum : NSUInteger {
|
|||
// and won't update the UI state immediately.
|
||||
- (void)didScrollToBottom
|
||||
{
|
||||
|
||||
id<ConversationViewItem> _Nullable lastVisibleViewItem = [self.viewItems lastObject];
|
||||
if (lastVisibleViewItem) {
|
||||
uint64_t lastVisibleSortId = lastVisibleViewItem.interaction.sortId;
|
||||
|
|
|
@ -63,8 +63,16 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
interactionIndexMap[viewItem.interaction.uniqueId] = @(i);
|
||||
[interactionIds addObject:viewItem.interaction.uniqueId];
|
||||
|
||||
if (viewItem.unreadIndicator != nil) {
|
||||
_unreadIndicatorIndex = @(i);
|
||||
if (viewItem.unreadIndicator != nil && [viewItem.interaction conformsToProtocol:@protocol(OWSReadTracking)]) {
|
||||
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];
|
||||
|
|
|
@ -348,7 +348,12 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa
|
|||
OWSFailDebug(@"Unexpected object in unseen messages: %@", [object class]);
|
||||
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];
|
||||
|
@ -356,7 +361,24 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa
|
|||
|
||||
- (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
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#import "TSThread.h"
|
||||
#import "UIImage+OWS.h"
|
||||
#import <YapDatabase/YapDatabase.h>
|
||||
#import <SessionServiceKit/SessionServiceKit-Swift.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
|
@ -65,6 +66,30 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
- (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;
|
||||
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
||||
numberOfItems = [[transaction ext:TSUnreadDatabaseViewExtensionName] numberOfItemsInAllGroups];
|
||||
|
|
|
@ -491,7 +491,10 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
|
|||
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);
|
||||
if (!possiblyRead.read) {
|
||||
[newlyReadList addObject:possiblyRead];
|
||||
|
|
Loading…
Reference in New Issue