crashfix: crash while accessing image property

assert on blind cast

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent 2eaaba9082
commit bb8f6c1b73

@ -2202,33 +2202,38 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
if ([[messageItem media] isKindOfClass:[TSPhotoAdapter class]]) { if ([[messageItem media] isKindOfClass:[TSPhotoAdapter class]]) {
TSPhotoAdapter *messageMedia = (TSPhotoAdapter *)[messageItem media]; TSPhotoAdapter *messageMedia = (TSPhotoAdapter *)[messageItem media];
UIImage *tappedImage = ((UIImageView *)[messageMedia mediaView]).image; UIView *mediaView = [messageMedia mediaView];
if (![mediaView isKindOfClass:[UIImageView class]]) {
OWSFail(@"unexpected mediaView of type: %@", [mediaView class]);
return;
}
UIImageView *imageView = (UIImageView *)mediaView;
UIImage *tappedImage = imageView.image;
if (tappedImage == nil) { if (tappedImage == nil) {
DDLogWarn(@"tapped TSPhotoAdapter with nil image"); DDLogWarn(@"tapped TSPhotoAdapter with nil image");
} else { return;
UIWindow *window = [UIApplication sharedApplication].keyWindow; }
JSQMessagesCollectionViewCell *cell UIWindow *window = [UIApplication sharedApplication].keyWindow;
= (JSQMessagesCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath]; JSQMessagesCollectionViewCell *cell
OWSAssert([cell isKindOfClass:[JSQMessagesCollectionViewCell class]]); = (JSQMessagesCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
CGRect convertedRect = [cell.mediaView convertRect:cell.mediaView.bounds toView:window]; OWSAssert([cell isKindOfClass:[JSQMessagesCollectionViewCell class]]);
CGRect convertedRect = [cell.mediaView convertRect:cell.mediaView.bounds toView:window];
__block TSAttachment *attachment = nil; __block TSAttachment *attachment = nil;
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
attachment = [TSAttachment fetchObjectWithUniqueID:messageMedia.attachmentId attachment =
transaction:transaction]; [TSAttachment fetchObjectWithUniqueID:messageMedia.attachmentId transaction:transaction];
}]; }];
if ([attachment isKindOfClass:[TSAttachmentStream class]]) { if ([attachment isKindOfClass:[TSAttachmentStream class]]) {
TSAttachmentStream *attStream = (TSAttachmentStream *)attachment; TSAttachmentStream *attStream = (TSAttachmentStream *)attachment;
FullImageViewController *vc = FullImageViewController *vc = [[FullImageViewController alloc] initWithAttachment:attStream
[[FullImageViewController alloc] initWithAttachment:attStream fromRect:convertedRect
fromRect:convertedRect forInteraction:interaction
forInteraction:interaction messageItem:messageItem
messageItem:messageItem isAnimated:NO];
isAnimated:NO];
[vc presentFromViewController:self]; [vc presentFromViewController:self];
}
} }
} else if ([[messageItem media] isKindOfClass:[TSAnimatedAdapter class]]) { } else if ([[messageItem media] isKindOfClass:[TSAnimatedAdapter class]]) {
// Show animated image full-screen // Show animated image full-screen

Loading…
Cancel
Save