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;
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Add table
Reference in a new issue