Update attachment handling

This commit is contained in:
trevor-signal 2024-12-11 14:56:41 -05:00 committed by GitHub
parent 6f7faf4be8
commit 6c348e2db7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 34 additions and 22 deletions

View file

@ -5,7 +5,7 @@ import * as Bytes from '../Bytes';
import type { AttachmentDownloadJobTypeType } from '../types/AttachmentDownload';
import type { AttachmentType } from '../types/Attachment';
import { getAttachmentSignature, isDownloaded } from '../types/Attachment';
import { getAttachmentSignatureSafe, isDownloaded } from '../types/Attachment';
import { __DEPRECATED$getMessageById } from '../messages/getMessageById';
export async function addAttachmentToMessage(
@ -21,7 +21,10 @@ export async function addAttachmentToMessage(
return;
}
const attachmentSignature = getAttachmentSignature(attachment);
const attachmentSignature = getAttachmentSignatureSafe(attachment);
if (!attachmentSignature) {
log.error(`${logPrefix}: Attachment did not have valid signature (digest)`);
}
if (type === 'long-message') {
let handledAnywhere = false;
@ -45,7 +48,8 @@ export async function addAttachmentToMessage(
}
// This attachment isn't destined for this edit
if (
getAttachmentSignature(edit.bodyAttachment) !== attachmentSignature
getAttachmentSignatureSafe(edit.bodyAttachment) !==
attachmentSignature
) {
return edit;
}
@ -79,7 +83,8 @@ export async function addAttachmentToMessage(
return;
}
if (
getAttachmentSignature(existingBodyAttachment) !== attachmentSignature
getAttachmentSignatureSafe(existingBodyAttachment) !==
attachmentSignature
) {
return;
}
@ -116,7 +121,7 @@ export async function addAttachmentToMessage(
return existing;
}
if (attachmentSignature !== getAttachmentSignature(existing)) {
if (attachmentSignature !== getAttachmentSignatureSafe(existing)) {
return existing;
}
@ -322,7 +327,7 @@ export async function addAttachmentToMessage(
message.set({
sticker: {
...sticker,
data: attachment,
data: sticker.data ? maybeReplaceAttachment(sticker.data) : attachment,
},
});
return;