From fc330ef854fe0ffc6e153ba6ba7383261eae6e76 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Thu, 12 Apr 2018 12:00:31 -0700 Subject: [PATCH] Quote loading: Check for in-memory message until we get one --- js/models/conversations.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index a5e63549b..8d093752d 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -1148,14 +1148,14 @@ return; } - // We've already gone through this method once for this message - if (message.quoteIsProcessed) { + // If we already have a quoted message, then we exit early. If we don't have it, + // then we'll continue to look again for an in-memory message to use. Why? This + // will enable us to scroll to it when the user clicks. + if (messages.quotedMessage) { return; } - // eslint-disable-next-line no-param-reassign - message.quoteIsProcessed = true; - // First, check to see if we've already loaded the target message into memory + // 1. Check to see if we've already loaded the target message into memory const { author, id } = quote; const key = this.makeKey(author, id); const quotedMessage = lookup[key]; @@ -1167,13 +1167,20 @@ return; } - // Then go to the database for the real referenced attachment + // We've don't want to go to the database or load thumbnails a second time. + if (message.quoteIsProcessed) { + return; + } + // eslint-disable-next-line no-param-reassign + message.quoteIsProcessed = true; + + // 2. Go to the database for the real referenced attachment const loaded = await this.loadQuotedMessageFromDatabase(message, id); if (loaded) { return; } - // Finally, use the provided thumbnail + // 3. Finally, use the provided thumbnail await this.loadQuoteThumbnail(message, quote); });