From 605ddb7b3e93fcb79169951651904d39edd4c67b Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Tue, 18 Mar 2025 07:32:41 +1000 Subject: [PATCH] Ensure that send proceeds even if quote thumbnail attachment not found --- ts/jobs/helpers/sendNormalMessage.ts | 40 +++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/ts/jobs/helpers/sendNormalMessage.ts b/ts/jobs/helpers/sendNormalMessage.ts index 5de5c6c4f..5233c7f17 100644 --- a/ts/jobs/helpers/sendNormalMessage.ts +++ b/ts/jobs/helpers/sendNormalMessage.ts @@ -38,6 +38,7 @@ import type { ConversationQueueJobBundle, NormalMessageSendJobData, } from '../conversationJobQueue'; +import type { QuotedMessageType } from '../../model-types.d'; import { handleMultipleSendErrors } from './handleMultipleSendErrors'; import { ourProfileKeyService } from '../../services/ourProfileKey'; @@ -844,10 +845,43 @@ async function uploadMessageQuote({ prop: 'quote', targetTimestamp, }); - const loadedQuote = await loadQuoteData(startingQuote); + let loadedQuote: QuotedMessageType | null; - if (!loadedQuote) { - return undefined; + // We are resilient to this because it's easy for quote thumbnails to be deleted out + // from under us, since the attachment is shared with the original message. Delete for + // Everyone on the original message, and the shared attachment will be deleted. + try { + loadedQuote = await loadQuoteData(startingQuote); + if (!loadedQuote) { + return undefined; + } + } catch (error) { + log.error( + 'uplodateMessageQuote: Failed to load quote thumbnail', + Errors.toLogFormat(error) + ); + if (!startingQuote) { + return undefined; + } + + return { + isGiftBadge: startingQuote.isGiftBadge, + id: startingQuote.id ?? undefined, + authorAci: startingQuote.authorAci + ? normalizeAci( + startingQuote.authorAci, + 'sendNormalMessage.quote.authorAci' + ) + : undefined, + text: startingQuote.text, + bodyRanges: startingQuote.bodyRanges, + attachments: (startingQuote.attachments || []).map(attachment => { + return { + contentType: attachment.contentType, + fileName: attachment.fileName, + }; + }), + }; } const attachmentsAfterThumbnailUpload = await uploadQueue.addAll(