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;
|
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(
|
export async function handleEditMessage(
|
||||||
mainMessage: MessageAttributesType,
|
mainMessage: MessageAttributesType,
|
||||||
editAttributes: Pick<
|
editAttributes: Pick<
|
||||||
|
@ -129,7 +143,7 @@ export async function handleEditMessage(
|
||||||
const quoteSignatures: Map<string, AttachmentType> = new Map();
|
const quoteSignatures: Map<string, AttachmentType> = new Map();
|
||||||
|
|
||||||
mainMessage.attachments?.forEach(attachment => {
|
mainMessage.attachments?.forEach(attachment => {
|
||||||
const signature = getAttachmentSignature(attachment);
|
const signature = getAttachmentSignatureSafe(attachment);
|
||||||
if (signature) {
|
if (signature) {
|
||||||
attachmentSignatures.set(signature, attachment);
|
attachmentSignatures.set(signature, attachment);
|
||||||
}
|
}
|
||||||
|
@ -138,7 +152,7 @@ export async function handleEditMessage(
|
||||||
if (!preview.image) {
|
if (!preview.image) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const signature = getAttachmentSignature(preview.image);
|
const signature = getAttachmentSignatureSafe(preview.image);
|
||||||
if (signature) {
|
if (signature) {
|
||||||
previewSignatures.set(signature, preview);
|
previewSignatures.set(signature, preview);
|
||||||
}
|
}
|
||||||
|
@ -148,7 +162,7 @@ export async function handleEditMessage(
|
||||||
if (!attachment.thumbnail) {
|
if (!attachment.thumbnail) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const signature = getAttachmentSignature(attachment.thumbnail);
|
const signature = getAttachmentSignatureSafe(attachment.thumbnail);
|
||||||
if (signature) {
|
if (signature) {
|
||||||
quoteSignatures.set(signature, attachment);
|
quoteSignatures.set(signature, attachment);
|
||||||
}
|
}
|
||||||
|
@ -158,7 +172,7 @@ export async function handleEditMessage(
|
||||||
let newAttachments = 0;
|
let newAttachments = 0;
|
||||||
const nextEditedMessageAttachments =
|
const nextEditedMessageAttachments =
|
||||||
upgradedEditedMessageData.attachments?.map(attachment => {
|
upgradedEditedMessageData.attachments?.map(attachment => {
|
||||||
const signature = getAttachmentSignature(attachment);
|
const signature = getAttachmentSignatureSafe(attachment);
|
||||||
const existingAttachment = signature
|
const existingAttachment = signature
|
||||||
? attachmentSignatures.get(signature)
|
? attachmentSignatures.get(signature)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
@ -178,7 +192,7 @@ export async function handleEditMessage(
|
||||||
return preview;
|
return preview;
|
||||||
}
|
}
|
||||||
|
|
||||||
const signature = getAttachmentSignature(preview.image);
|
const signature = getAttachmentSignatureSafe(preview.image);
|
||||||
const existingPreview = signature
|
const existingPreview = signature
|
||||||
? previewSignatures.get(signature)
|
? previewSignatures.get(signature)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
@ -208,7 +222,7 @@ export async function handleEditMessage(
|
||||||
if (!attachment.thumbnail) {
|
if (!attachment.thumbnail) {
|
||||||
return attachment;
|
return attachment;
|
||||||
}
|
}
|
||||||
const signature = getAttachmentSignature(attachment.thumbnail);
|
const signature = getAttachmentSignatureSafe(attachment.thumbnail);
|
||||||
const existingThumbnail = signature
|
const existingThumbnail = signature
|
||||||
? quoteSignatures.get(signature)
|
? quoteSignatures.get(signature)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
|
@ -40,6 +40,20 @@ export type MessageAttachmentsDownloadedType = {
|
||||||
sticker?: StickerType;
|
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
|
// Receive logic
|
||||||
// NOTE: If you're changing any logic in this function that deals with the
|
// NOTE: If you're changing any logic in this function that deals with the
|
||||||
// count then you'll also have to modify ./hasAttachmentsDownloads
|
// count then you'll also have to modify ./hasAttachmentsDownloads
|
||||||
|
@ -273,7 +287,7 @@ async function queueNormalAttachments(
|
||||||
// then not be added to the AttachmentDownloads job.
|
// then not be added to the AttachmentDownloads job.
|
||||||
const attachmentSignatures: Map<string, AttachmentType> = new Map();
|
const attachmentSignatures: Map<string, AttachmentType> = new Map();
|
||||||
otherAttachments?.forEach(attachment => {
|
otherAttachments?.forEach(attachment => {
|
||||||
const signature = getAttachmentSignature(attachment);
|
const signature = getAttachmentSignatureSafe(attachment);
|
||||||
if (signature) {
|
if (signature) {
|
||||||
attachmentSignatures.set(signature, attachment);
|
attachmentSignatures.set(signature, attachment);
|
||||||
}
|
}
|
||||||
|
@ -291,7 +305,7 @@ async function queueNormalAttachments(
|
||||||
return attachment;
|
return attachment;
|
||||||
}
|
}
|
||||||
|
|
||||||
const signature = getAttachmentSignature(attachment);
|
const signature = getAttachmentSignatureSafe(attachment);
|
||||||
const existingAttachment = signature
|
const existingAttachment = signature
|
||||||
? attachmentSignatures.get(signature)
|
? attachmentSignatures.get(signature)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
@ -332,7 +346,12 @@ function getLinkPreviewSignature(preview: LinkPreviewType): string | undefined {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `<${url}>${getAttachmentSignature(image)}`;
|
const signature = getAttachmentSignatureSafe(image);
|
||||||
|
if (!signature) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `<${url}>${signature}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function queuePreviews(
|
async function queuePreviews(
|
||||||
|
@ -406,7 +425,11 @@ function getQuoteThumbnailSignature(
|
||||||
if (!thumbnail) {
|
if (!thumbnail) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return `<${quote.id}>${getAttachmentSignature(thumbnail)}`;
|
const signature = getAttachmentSignatureSafe(thumbnail);
|
||||||
|
if (!signature) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return `<${quote.id}>${signature}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function queueQuoteAttachments(
|
async function queueQuoteAttachments(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue