From d562a885837846473cfc185a3ac87bd417f7ffcf Mon Sep 17 00:00:00 2001 From: Maxim Shishmarev Date: Mon, 25 Nov 2019 16:27:48 +1100 Subject: [PATCH] Check again for quoted messages after a short timeout --- js/models/messages.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/js/models/messages.js b/js/models/messages.js index 30a8be424..1973974af 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -1674,7 +1674,7 @@ return false; }, - async copyFromQuotedMessage(message) { + async copyFromQuotedMessage(message, attemptCount = 1) { const { quote } = message; if (!quote) { return message; @@ -1693,12 +1693,36 @@ }); if (!found) { + // Exponential backoff, giving up after 5 attempts: + if (attemptCount < 5) { + setTimeout(() => { + window.log.info( + `Looking for the message id : ${id}, attempt: ${attemptCount + 1}` + ); + this.copyFromQuotedMessage(message, attemptCount + 1); + }, attemptCount * attemptCount * 500); + } + quote.referencedMessageNotFound = true; return message; } + window.log.info(`Found quoted message id: ${id}`); + quote.referencedMessageNotFound = false; + const queryMessage = MessageController.register(found.id, found); quote.text = queryMessage.get('body'); + + if (attemptCount > 1) { + // Normally the caller would save the message, but in case we are + // called by a timer, we need to update the message manually + this.set({ quote }); + await window.Signal.Data.saveMessage(this.attributes, { + Message: Whisper.Message, + }); + return null; + } + if (firstAttachment) { firstAttachment.thumbnail = null; }