diff --git a/js/models/messages.js b/js/models/messages.js index eaed842cf..de8e7cc08 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -1714,7 +1714,7 @@ return false; }, - async copyFromQuotedMessage(message) { + async copyFromQuotedMessage(message, attemptCount = 1) { const { quote } = message; if (!quote) { return message; @@ -1733,12 +1733,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; }