Add asserts around attachment crash.

This commit is contained in:
Matthew Chen 2018-12-20 16:45:50 -05:00
parent 4a84a19d00
commit 1260e7459d
2 changed files with 21 additions and 3 deletions

View file

@ -8,6 +8,7 @@
#import <SignalServiceKit/MimeTypeUtil.h>
#import <SignalServiceKit/SignalServiceKit-Swift.h>
#import <YapDatabase/YapDatabase.h>
#import <YapDatabase/YapDatabaseTransaction.h>
NS_ASSUME_NONNULL_BEGIN
@ -209,6 +210,22 @@ NS_ASSUME_NONNULL_BEGIN
}];
}
- (void)saveWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
{
#ifdef DEBUG
if (self.uniqueId.length > 0) {
id _Nullable oldObject = [transaction objectForKey:self.uniqueId inCollection:TSAttachment.collection];
if ([oldObject isKindOfClass:[TSAttachmentStream class]]) {
OWSFailDebug(@"We should never overwrite a TSAttachmentStream with a TSAttachmentPointer.");
}
} else {
OWSFailDebug(@"Missing uniqueId.");
}
#endif
[super saveWithTransaction:transaction];
}
@end
NS_ASSUME_NONNULL_END

View file

@ -524,10 +524,11 @@ typedef void (^OWSLoadedThumbnailSuccess)(OWSLoadedThumbnail *loadedThumbnail);
self.cachedImageHeight = @(imageSize.height);
[self.dbReadWriteConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
NSString *collection = [[self class] collection];
NSString *collection = [TSAttachmentStream collection];
TSAttachmentStream *latestInstance = [transaction objectForKey:self.uniqueId inCollection:collection];
if (latestInstance) {
if (![latestInstance isKindOfClass:[TSAttachmentStream class]]) {
OWSFailDebug(@"Attachment has unexpected type: %@", latestInstance.class);
} else if (latestInstance) {
latestInstance.cachedImageWidth = @(imageSize.width);
latestInstance.cachedImageHeight = @(imageSize.height);
[latestInstance saveWithTransaction:transaction];