Grab freshest attributes when adding attachment to message

This commit is contained in:
trevor-signal 2024-05-15 10:19:55 -04:00 committed by GitHub
parent 32fda78a5c
commit ad94fef92d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 8 deletions

View file

@ -518,7 +518,7 @@ async function runDownloadAttachmentJob(
if (error instanceof AttachmentSizeError) { if (error instanceof AttachmentSizeError) {
await addAttachmentToMessage( await addAttachmentToMessage(
message, message.id,
_markAttachmentAsTooBig(job.attachment), _markAttachmentAsTooBig(job.attachment),
logId, logId,
{ type: job.attachmentType } { type: job.attachmentType }
@ -528,7 +528,7 @@ async function runDownloadAttachmentJob(
if (error instanceof AttachmentNotFoundOnCdnError) { if (error instanceof AttachmentNotFoundOnCdnError) {
await addAttachmentToMessage( await addAttachmentToMessage(
message, message.id,
_markAttachmentAsPermanentlyErrored(job.attachment), _markAttachmentAsPermanentlyErrored(job.attachment),
logId, logId,
{ type: job.attachmentType } { type: job.attachmentType }
@ -539,7 +539,7 @@ async function runDownloadAttachmentJob(
if (isLastAttempt) { if (isLastAttempt) {
await addAttachmentToMessage( await addAttachmentToMessage(
message, message.id,
_markAttachmentAsTransientlyErrored(job.attachment), _markAttachmentAsTransientlyErrored(job.attachment),
logId, logId,
{ type: job.attachmentType } { type: job.attachmentType }
@ -549,7 +549,7 @@ async function runDownloadAttachmentJob(
// Remove `pending` flag from the attachment and retry later // Remove `pending` flag from the attachment and retry later
await addAttachmentToMessage( await addAttachmentToMessage(
message, message.id,
{ {
...job.attachment, ...job.attachment,
pending: false, pending: false,
@ -601,7 +601,7 @@ async function runDownloadAttachmentJobInner(
} }
await addAttachmentToMessage( await addAttachmentToMessage(
message, message.id,
{ ...attachment, pending: true }, { ...attachment, pending: true },
logId, logId,
{ type } { type }
@ -613,7 +613,7 @@ async function runDownloadAttachmentJobInner(
await window.Signal.Migrations.processNewAttachment(downloaded); await window.Signal.Migrations.processNewAttachment(downloaded);
await addAttachmentToMessage( await addAttachmentToMessage(
message, message.id,
omit(upgradedAttachment, ['error', 'pending']), omit(upgradedAttachment, ['error', 'pending']),
logId, logId,
{ {

View file

@ -4,16 +4,18 @@ import * as log from '../logging/log';
import * as Bytes from '../Bytes'; import * as Bytes from '../Bytes';
import type { AttachmentDownloadJobTypeType } from '../types/AttachmentDownload'; import type { AttachmentDownloadJobTypeType } from '../types/AttachmentDownload';
import type { MessageModel } from '../models/messages';
import type { AttachmentType } from '../types/Attachment'; import type { AttachmentType } from '../types/Attachment';
import { getAttachmentSignature, isDownloaded } from '../types/Attachment'; import { getAttachmentSignature, isDownloaded } from '../types/Attachment';
import { __DEPRECATED$getMessageById } from '../messages/getMessageById';
export async function addAttachmentToMessage( export async function addAttachmentToMessage(
message: MessageModel | null | undefined, messageId: string,
attachment: AttachmentType, attachment: AttachmentType,
jobLogId: string, jobLogId: string,
{ type }: { type: AttachmentDownloadJobTypeType } { type }: { type: AttachmentDownloadJobTypeType }
): Promise<void> { ): Promise<void> {
const message = await __DEPRECATED$getMessageById(messageId);
if (!message) { if (!message) {
return; return;
} }