Safely ignore invalid link preview images.
This commit is contained in:
parent
673588a98c
commit
9c806d59df
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue