From 403fb1fd60f9fa4df8800aa3da2f074567b8d878 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Thu, 26 Apr 2018 12:00:57 -0700 Subject: [PATCH] Make algorithm for finding thumbnails more efficient --- js/models/conversations.js | 17 ++++++++++++----- js/views/file_input_view.js | 4 +++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index 15fb7fa8b..aea404a6f 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -1159,8 +1159,8 @@ const { attachments, id, author } = quote; const first = attachments[0]; - if (!first || first.thumbnail) { - return true; + if (!first || message.quoteThumbnail) { + return false; } if (!Signal.Util.GoogleChrome.isImageTypeSupported(first.contentType) && @@ -1202,7 +1202,7 @@ const { attachments } = quote; const first = attachments[0]; - if (!first || first.thumbnail) { + if (!first || message.quoteThumbnail) { return; } @@ -1232,7 +1232,8 @@ const { quote } = message.attributes; const { attachments } = quote; const first = attachments[0]; - if (!first) { + + if (!first || message.quoteThumbnail) { return false; } @@ -1292,6 +1293,12 @@ return; } + // No need to go further if we already have a thumbnail + if (gotThumbnail) { + this.forceRender(message); + return; + } + // We only go further if we need more data for this message. It's always important // to grab the quoted message to allow for navigating to it by clicking. const { attachments } = quote; @@ -1300,7 +1307,7 @@ } // We've don't want to go to the database or load thumbnails a second time. - if (message.quoteIsProcessed || gotThumbnail) { + if (message.quoteIsProcessed) { return; } // eslint-disable-next-line no-param-reassign diff --git a/js/views/file_input_view.js b/js/views/file_input_view.js index 151f99b34..190d168cf 100644 --- a/js/views/file_input_view.js +++ b/js/views/file_input_view.js @@ -117,7 +117,9 @@ const arrayBuffer = await blobToArrayBuffer(blob); const screenshotObjectUrl = makeObjectUrl(arrayBuffer, 'image/png'); - return makeImageThumbnail(size, screenshotObjectUrl); + const thumbnail = await makeImageThumbnail(size, screenshotObjectUrl); + URL.revokeObjectURL(screenshotObjectUrl); + return thumbnail; } Whisper.FileInputView = Backbone.View.extend({