From ad94fef92d59ccdcf803afe9f7c62a75888236ef Mon Sep 17 00:00:00 2001 From: trevor-signal <131492920+trevor-signal@users.noreply.github.com> Date: Wed, 15 May 2024 10:19:55 -0400 Subject: [PATCH] Grab freshest attributes when adding attachment to message --- ts/jobs/AttachmentDownloadManager.ts | 12 ++++++------ ts/messageModifiers/AttachmentDownloads.ts | 6 ++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/ts/jobs/AttachmentDownloadManager.ts b/ts/jobs/AttachmentDownloadManager.ts index 311281249a77..f981c1836c63 100644 --- a/ts/jobs/AttachmentDownloadManager.ts +++ b/ts/jobs/AttachmentDownloadManager.ts @@ -518,7 +518,7 @@ async function runDownloadAttachmentJob( if (error instanceof AttachmentSizeError) { await addAttachmentToMessage( - message, + message.id, _markAttachmentAsTooBig(job.attachment), logId, { type: job.attachmentType } @@ -528,7 +528,7 @@ async function runDownloadAttachmentJob( if (error instanceof AttachmentNotFoundOnCdnError) { await addAttachmentToMessage( - message, + message.id, _markAttachmentAsPermanentlyErrored(job.attachment), logId, { type: job.attachmentType } @@ -539,7 +539,7 @@ async function runDownloadAttachmentJob( if (isLastAttempt) { await addAttachmentToMessage( - message, + message.id, _markAttachmentAsTransientlyErrored(job.attachment), logId, { type: job.attachmentType } @@ -549,7 +549,7 @@ async function runDownloadAttachmentJob( // Remove `pending` flag from the attachment and retry later await addAttachmentToMessage( - message, + message.id, { ...job.attachment, pending: false, @@ -601,7 +601,7 @@ async function runDownloadAttachmentJobInner( } await addAttachmentToMessage( - message, + message.id, { ...attachment, pending: true }, logId, { type } @@ -613,7 +613,7 @@ async function runDownloadAttachmentJobInner( await window.Signal.Migrations.processNewAttachment(downloaded); await addAttachmentToMessage( - message, + message.id, omit(upgradedAttachment, ['error', 'pending']), logId, { diff --git a/ts/messageModifiers/AttachmentDownloads.ts b/ts/messageModifiers/AttachmentDownloads.ts index fa9ff3203675..0e13645878ed 100644 --- a/ts/messageModifiers/AttachmentDownloads.ts +++ b/ts/messageModifiers/AttachmentDownloads.ts @@ -4,16 +4,18 @@ import * as log from '../logging/log'; import * as Bytes from '../Bytes'; import type { AttachmentDownloadJobTypeType } from '../types/AttachmentDownload'; -import type { MessageModel } from '../models/messages'; import type { AttachmentType } from '../types/Attachment'; import { getAttachmentSignature, isDownloaded } from '../types/Attachment'; +import { __DEPRECATED$getMessageById } from '../messages/getMessageById'; export async function addAttachmentToMessage( - message: MessageModel | null | undefined, + messageId: string, attachment: AttachmentType, jobLogId: string, { type }: { type: AttachmentDownloadJobTypeType } ): Promise { + const message = await __DEPRECATED$getMessageById(messageId); + if (!message) { return; }