diff --git a/fluxer_api/src/api/channel/services/message/MessageHelpers.ts b/fluxer_api/src/api/channel/services/message/MessageHelpers.ts index c1c9f3c6b..bdbcbcf81 100644 --- a/fluxer_api/src/api/channel/services/message/MessageHelpers.ts +++ b/fluxer_api/src/api/channel/services/message/MessageHelpers.ts @@ -308,7 +308,7 @@ export async function createMessageSnapshotsForForward( return [new MessageSnapshotModel(snapshotData)]; } -function collectEmbedReferencedAttachmentCdnKeys(message: Message): Array { +function collectEmbedReferencedAttachmentCdnKeys(message: Message, ownKeys: ReadonlySet): Array { const mediaPrefix = `${Config.endpoints.media}/`; const keys = new Set(); const consider = (url: string | null | undefined): void => { @@ -316,7 +316,7 @@ function collectEmbedReferencedAttachmentCdnKeys(message: Message): Array { const cdnKeys = new Set(); const cdnUrls: Array = []; + const ownedCdnKeys = new Set( + collectMessageAttachments(message).map((attachment) => + makeAttachmentCdnKey(message.channelId, attachment.id, attachment.filename), + ), + ); for (const attachment of collectMessageAttachments(message)) { const cdnKey = makeAttachmentCdnKey(message.channelId, attachment.id, attachment.filename); if (cdnKeys.has(cdnKey)) { @@ -352,7 +357,7 @@ export async function purgeMessageAttachments( cdnUrls.push(makeAttachmentCdnUrl(message.channelId, attachment.id, attachment.filename)); } } - for (const embedKey of collectEmbedReferencedAttachmentCdnKeys(message)) { + for (const embedKey of collectEmbedReferencedAttachmentCdnKeys(message, ownedCdnKeys)) { if (cdnKeys.has(embedKey)) { continue; }