diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m index 539788ee5..fa13720a0 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m @@ -669,10 +669,21 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType) if (self.hasBodyText && attachment == nil && message.linkPreview) { self.linkPreview = message.linkPreview; if (message.linkPreview.imageAttachmentId.length > 0) { - self.linkPreviewAttachment = + TSAttachment *_Nullable linkPreviewAttachment = [TSAttachment fetchObjectWithUniqueID:message.linkPreview.imageAttachmentId transaction:transaction]; - if (!self.linkPreviewAttachment) { + if (!linkPreviewAttachment) { OWSFailDebug(@"Could not load link preview image attachment."); + } else if (!linkPreviewAttachment.isImage) { + OWSFailDebug(@"Link preview attachment isn't an image."); + } else if ([linkPreviewAttachment isKindOfClass:[TSAttachmentStream class]]) { + TSAttachmentStream *attachmentStream = (TSAttachmentStream *)linkPreviewAttachment; + if (!attachmentStream.isValidImage) { + OWSFailDebug(@"Link preview image attachment isn't valid."); + } else { + self.linkPreviewAttachment = linkPreviewAttachment; + } + } else { + self.linkPreviewAttachment = linkPreviewAttachment; } } } diff --git a/Signal/src/views/LinkPreviewView.swift b/Signal/src/views/LinkPreviewView.swift index f5395683c..2f1448ca0 100644 --- a/Signal/src/views/LinkPreviewView.swift +++ b/Signal/src/views/LinkPreviewView.swift @@ -188,7 +188,8 @@ public class LinkPreviewSent: NSObject, LinkPreviewState { guard let attachmentStream = imageAttachment as? TSAttachmentStream else { return .loading } - guard attachmentStream.isValidImage else { + guard attachmentStream.isImage, + attachmentStream.isValidImage else { return .invalid } return .loaded @@ -201,7 +202,8 @@ public class LinkPreviewSent: NSObject, LinkPreviewState { owsFailDebug("Could not load image.") return nil } - guard attachmentStream.isValidImage else { + guard attachmentStream.isImage, + attachmentStream.isValidImage else { return nil } guard let imageFilepath = attachmentStream.originalFilePath else {