Do not drop edit messages if we get an invalid attachment

This commit is contained in:
Josh Perez 2023-10-05 12:16:50 -04:00 committed by GitHub
parent 4973dac57a
commit b4b3883850
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 10 deletions

View file

@ -40,6 +40,20 @@ export type MessageAttachmentsDownloadedType = {
sticker?: StickerType;
};
function getAttachmentSignatureSafe(
attachment: AttachmentType
): string | undefined {
try {
return getAttachmentSignature(attachment);
} catch {
log.warn(
'queueAttachmentDownloads: attachment was missing digest',
attachment.blurHash
);
return undefined;
}
}
// Receive logic
// NOTE: If you're changing any logic in this function that deals with the
// count then you'll also have to modify ./hasAttachmentsDownloads
@ -273,7 +287,7 @@ async function queueNormalAttachments(
// then not be added to the AttachmentDownloads job.
const attachmentSignatures: Map<string, AttachmentType> = new Map();
otherAttachments?.forEach(attachment => {
const signature = getAttachmentSignature(attachment);
const signature = getAttachmentSignatureSafe(attachment);
if (signature) {
attachmentSignatures.set(signature, attachment);
}
@ -291,7 +305,7 @@ async function queueNormalAttachments(
return attachment;
}
const signature = getAttachmentSignature(attachment);
const signature = getAttachmentSignatureSafe(attachment);
const existingAttachment = signature
? attachmentSignatures.get(signature)
: undefined;
@ -332,7 +346,12 @@ function getLinkPreviewSignature(preview: LinkPreviewType): string | undefined {
return;
}
return `<${url}>${getAttachmentSignature(image)}`;
const signature = getAttachmentSignatureSafe(image);
if (!signature) {
return;
}
return `<${url}>${signature}`;
}
async function queuePreviews(
@ -406,7 +425,11 @@ function getQuoteThumbnailSignature(
if (!thumbnail) {
return undefined;
}
return `<${quote.id}>${getAttachmentSignature(thumbnail)}`;
const signature = getAttachmentSignatureSafe(thumbnail);
if (!signature) {
return;
}
return `<${quote.id}>${signature}`;
}
async function queueQuoteAttachments(