Skip to content

Commit

Permalink
Send/reply: Be resilient to errors making attachment thumbnail (#2468)
Browse files Browse the repository at this point in the history
* Show generic file icon if we fail to make attachment thumbnail

* Be resilient to thumbnail creation errors when creating quote
  • Loading branch information
scottnonnenberg-signal committed Jun 21, 2018
1 parent 8eeaad8 commit a460380
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
18 changes: 15 additions & 3 deletions js/models/conversations.js
Original file line number Diff line number Diff line change
Expand Up @@ -735,13 +735,25 @@
const willMakeThumbnail =
Signal.Util.GoogleChrome.isImageTypeSupported(contentType) ||
Signal.Util.GoogleChrome.isVideoTypeSupported(contentType);
const makeThumbnail = async () => {
try {
if (willMakeThumbnail) {
return await this.makeThumbnailAttachment(attachment);
}
} catch (error) {
console.log(
'Failed to create quote thumbnail',
error && error.stack ? error.stack : error
);
}

return null;
};

return {
contentType,
fileName: attachment.fileName,
thumbnail: willMakeThumbnail
? await this.makeThumbnailAttachment(attachment)
: null,
thumbnail: makeThumbnail(),
};
})
),
Expand Down
22 changes: 15 additions & 7 deletions js/views/file_input_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,21 @@
this.addThumb(dataUrl);
};

if (Signal.Util.GoogleChrome.isImageTypeSupported(contentType)) {
renderImagePreview();
} else if (Signal.Util.GoogleChrome.isVideoTypeSupported(contentType)) {
renderVideoPreview();
} else if (MIME.isAudio(contentType)) {
this.addThumb('images/audio.svg');
} else {
try {
if (Signal.Util.GoogleChrome.isImageTypeSupported(contentType)) {
await renderImagePreview();
} else if (Signal.Util.GoogleChrome.isVideoTypeSupported(contentType)) {
await renderVideoPreview();
} else if (MIME.isAudio(contentType)) {
this.addThumb('images/audio.svg');
} else {
this.addThumb('images/file.svg');
}
} catch (e) {
console.log(
`Was unable to generate thumbnail for file type ${contentType}`,
e && e.stack ? e.stack : e
);
this.addThumb('images/file.svg');
}

Expand Down

0 comments on commit a460380

Please sign in to comment.