diff --git a/Signal/src/ViewControllers/ConversationView/MessagesViewController.m b/Signal/src/ViewControllers/ConversationView/MessagesViewController.m index 2c97a138c..4d3bc4302 100644 --- a/Signal/src/ViewControllers/ConversationView/MessagesViewController.m +++ b/Signal/src/ViewControllers/ConversationView/MessagesViewController.m @@ -3956,20 +3956,30 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { TSThread *thread = self.thread; uint64_t lastVisibleTimestamp = self.lastVisibleTimestamp; + [self.editingDatabaseConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) { NSMutableArray> *interactions = [NSMutableArray new]; + [[TSDatabaseView unseenDatabaseViewExtension:transaction] enumerateRowsInGroup:thread.uniqueId usingBlock:^( NSString *collection, NSString *key, id object, id metadata, NSUInteger index, BOOL *stop) { - TSInteraction *interaction = object; - if (interaction.timestampForSorting > lastVisibleTimestamp) { + if (![object conformsToProtocol:@protocol(OWSReadTracking)]) { + OWSFail(@"Expected to conform to OWSReadTracking: object with class: %@ collection: %@ " + @"key: %@", + [object class], + collection, + key); + return; + } + id possiblyRead = (id)object; + + if (possiblyRead.timestampForSorting > lastVisibleTimestamp) { *stop = YES; return; } - id possiblyRead = (id)object; OWSAssert(!possiblyRead.read); if (!possiblyRead.read) { [interactions addObject:possiblyRead]; diff --git a/SignalServiceKit/src/Contacts/TSThread.m b/SignalServiceKit/src/Contacts/TSThread.m index 8acc9eead..d53150622 100644 --- a/SignalServiceKit/src/Contacts/TSThread.m +++ b/SignalServiceKit/src/Contacts/TSThread.m @@ -221,7 +221,8 @@ NS_ASSUME_NONNULL_BEGIN NSString *collection, NSString *key, id object, id metadata, NSUInteger index, BOOL *stop) { if (![object conformsToProtocol:@protocol(OWSReadTracking)]) { - DDLogError(@"%@ Unexpected object in unread messages: %@", self.tag, object); + OWSFail(@"%@ Unexpected object in unread messages: %@", self.tag, object); + return; } [messages addObject:(id)object]; }]; diff --git a/SignalServiceKit/src/Messages/OWSReadTracking.h b/SignalServiceKit/src/Messages/OWSReadTracking.h index 5236753bb..ed3dd27be 100644 --- a/SignalServiceKit/src/Messages/OWSReadTracking.h +++ b/SignalServiceKit/src/Messages/OWSReadTracking.h @@ -15,6 +15,7 @@ */ @property (nonatomic, readonly, getter=wasRead) BOOL read; +@property (nonatomic, readonly) uint64_t timestampForSorting; @property (nonatomic, readonly) NSString *uniqueThreadId; - (BOOL)shouldAffectUnreadCounts;