crashfix: on addObject, presumably it's nil.

I'm not sure how this is happening, but this will prevent the crash and
give us additional diagnostic data in the cases where it is happening.

// FREEBIE
This commit is contained in:
Michael Kirk 2017-08-31 11:49:21 -04:00
parent 274fa25e6d
commit 2eaaba9082
3 changed files with 16 additions and 4 deletions

View File

@ -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<id<OWSReadTracking>> *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<OWSReadTracking> possiblyRead = (id<OWSReadTracking>)object;
if (possiblyRead.timestampForSorting > lastVisibleTimestamp) {
*stop = YES;
return;
}
id<OWSReadTracking> possiblyRead = (id<OWSReadTracking>)object;
OWSAssert(!possiblyRead.read);
if (!possiblyRead.read) {
[interactions addObject:possiblyRead];

View File

@ -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<OWSReadTracking>)object];
}];

View File

@ -15,6 +15,7 @@
*/
@property (nonatomic, readonly, getter=wasRead) BOOL read;
@property (nonatomic, readonly) uint64_t timestampForSorting;
@property (nonatomic, readonly) NSString *uniqueThreadId;
- (BOOL)shouldAffectUnreadCounts;