Do not drop edit messages if we get an invalid attachment
This commit is contained in:
parent
4973dac57a
commit
b4b3883850
2 changed files with 47 additions and 10 deletions
|
@ -26,6 +26,20 @@ import { modifyTargetMessage } from './modifyTargetMessage';
|
|||
|
||||
const RECURSION_LIMIT = 15;
|
||||
|
||||
function getAttachmentSignatureSafe(
|
||||
attachment: AttachmentType
|
||||
): string | undefined {
|
||||
try {
|
||||
return getAttachmentSignature(attachment);
|
||||
} catch {
|
||||
log.warn(
|
||||
'handleEditMessage: attachment was missing digest',
|
||||
attachment.blurHash
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export async function handleEditMessage(
|
||||
mainMessage: MessageAttributesType,
|
||||
editAttributes: Pick<
|
||||
|
@ -129,7 +143,7 @@ export async function handleEditMessage(
|
|||
const quoteSignatures: Map<string, AttachmentType> = new Map();
|
||||
|
||||
mainMessage.attachments?.forEach(attachment => {
|
||||
const signature = getAttachmentSignature(attachment);
|
||||
const signature = getAttachmentSignatureSafe(attachment);
|
||||
if (signature) {
|
||||
attachmentSignatures.set(signature, attachment);
|
||||
}
|
||||
|
@ -138,7 +152,7 @@ export async function handleEditMessage(
|
|||
if (!preview.image) {
|
||||
return;
|
||||
}
|
||||
const signature = getAttachmentSignature(preview.image);
|
||||
const signature = getAttachmentSignatureSafe(preview.image);
|
||||
if (signature) {
|
||||
previewSignatures.set(signature, preview);
|
||||
}
|
||||
|
@ -148,7 +162,7 @@ export async function handleEditMessage(
|
|||
if (!attachment.thumbnail) {
|
||||
continue;
|
||||
}
|
||||
const signature = getAttachmentSignature(attachment.thumbnail);
|
||||
const signature = getAttachmentSignatureSafe(attachment.thumbnail);
|
||||
if (signature) {
|
||||
quoteSignatures.set(signature, attachment);
|
||||
}
|
||||
|
@ -158,7 +172,7 @@ export async function handleEditMessage(
|
|||
let newAttachments = 0;
|
||||
const nextEditedMessageAttachments =
|
||||
upgradedEditedMessageData.attachments?.map(attachment => {
|
||||
const signature = getAttachmentSignature(attachment);
|
||||
const signature = getAttachmentSignatureSafe(attachment);
|
||||
const existingAttachment = signature
|
||||
? attachmentSignatures.get(signature)
|
||||
: undefined;
|
||||
|
@ -178,7 +192,7 @@ export async function handleEditMessage(
|
|||
return preview;
|
||||
}
|
||||
|
||||
const signature = getAttachmentSignature(preview.image);
|
||||
const signature = getAttachmentSignatureSafe(preview.image);
|
||||
const existingPreview = signature
|
||||
? previewSignatures.get(signature)
|
||||
: undefined;
|
||||
|
@ -208,7 +222,7 @@ export async function handleEditMessage(
|
|||
if (!attachment.thumbnail) {
|
||||
return attachment;
|
||||
}
|
||||
const signature = getAttachmentSignature(attachment.thumbnail);
|
||||
const signature = getAttachmentSignatureSafe(attachment.thumbnail);
|
||||
const existingThumbnail = signature
|
||||
? quoteSignatures.get(signature)
|
||||
: undefined;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue