Fix crash

This commit is contained in:
Niels Andriesse 2021-07-30 10:44:48 +10:00
parent ec4ce64887
commit 556e13cc72
1 changed files with 10 additions and 6 deletions

View File

@ -72,11 +72,13 @@ NS_ASSUME_NONNULL_BEGIN
[LKStorage readWithBlock:^(YapDatabaseReadTransaction *transaction) {
YapDatabaseViewTransaction *unreadMessages = [transaction ext:TSUnreadDatabaseViewExtensionName];
NSArray<NSString *> *allGroups = [unreadMessages allGroups];
// FIXME: Confusingly, `allGroups` includes contact threads as well
for (NSString *groupID in allGroups) {
TSGroupThread *thread = [TSGroupThread fetchObjectWithUniqueID:groupID transaction:transaction];
if (thread.isMuted) continue;
TSThread *thread = [TSThread fetchObjectWithUniqueID:groupID transaction:transaction];
if (thread.isMuted) { continue; }
BOOL isGroupThread = thread.isGroupThread;
[unreadMessages enumerateKeysAndObjectsInGroup:groupID
usingBlock:^(NSString *collection, NSString *key, id object, NSUInteger index, BOOL *stop) {
usingBlock:^(NSString *collection, NSString *key, id object, NSUInteger index, BOOL *stop) {
if (![object conformsToProtocol:@protocol(OWSReadTracking)]) {
return;
}
@ -85,9 +87,11 @@ NS_ASSUME_NONNULL_BEGIN
NSLog(@"Found an already read message in the * unread * messages list.");
return;
}
TSIncomingMessage * incomingMessage = (TSIncomingMessage *)object;
if (incomingMessage != nil && thread.isOnlyNotifyingForMentions && !incomingMessage.isUserMentioned) {
return;
if ([object isKindOfClass:TSIncomingMessage.class] && isGroupThread) {
TSIncomingMessage *incomingMessage = (TSIncomingMessage *)object;
if (((TSGroupThread *)thread).isOnlyNotifyingForMentions && !incomingMessage.isUserMentioned) {
return;
}
}
count += 1;
}];