From db2c038f408ca75914711e80d6e8ba434daa07f7 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Tue, 11 Aug 2026 22:05:58 +1200 Subject: [PATCH] Support attachment spoiler flag --- package-lock.json | 6 +++--- src/d2m/converters/message-to-event.js | 13 ++++++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7d06709..986e6ca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1518,9 +1518,9 @@ } }, "node_modules/discord-api-types": { - "version": "0.38.52", - "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.38.52.tgz", - "integrity": "sha512-uwe9EKfbjsmgWc2fdFjvDbj+dQqx3lp7wqDCmIha0jInuU+xeQjkCK9tMMn+p7RXfdVQORCInq4cD3U2ymDmyg==", + "version": "0.38.53", + "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.38.53.tgz", + "integrity": "sha512-HL1zz/UuZ+bbJjA/X8Kbxx9gk8v9rJAbTeWRNYKmIdjwJ7EovjlHgoJTxcLpATfNJ+AonOtMdy3Y5MVIJAAd/A==", "license": "MIT", "workspaces": [ "scripts/actions/documentation" diff --git a/src/d2m/converters/message-to-event.js b/src/d2m/converters/message-to-event.js index b96f645..c0b9622 100644 --- a/src/d2m/converters/message-to-event.js +++ b/src/d2m/converters/message-to-event.js @@ -109,7 +109,7 @@ const embedTitleParser = markdown.markdownEngine.parserFor({ /** * @param {{room?: boolean, user_ids?: string[]}} mentions - * @param {Omit} attachment + * @param {Omit} attachment * @param {boolean} [alwaysLink] */ async function attachmentToEvent(mentions, attachment, alwaysLink) { @@ -122,7 +122,7 @@ async function attachmentToEvent(mentions, attachment, alwaysLink) { : attachment.content_type?.startsWith("audio/") ? "🎶" : "📄" // no native media spoilers in Element, so we'll post a link instead, forcing it to not preview using a blockquote - if (attachment.filename.startsWith("SPOILER_")) { + if (attachment.filename.startsWith("SPOILER_") || !!((attachment.flags || 0) & DiscordTypes.AttachmentFlags.IsSpoiler)) { return { $type: "m.room.message", "m.mentions": mentions, @@ -907,7 +907,14 @@ async function messageToEvent(message, guild, options = {}, di) { /** @type {{[k in keyof DiscordTypes.APIUnfurledMediaItem]-?: NonNullable}} */ // @ts-ignore const file = component.file assert(component.name && component.size && file.content_type) - const ev = await attachmentToEvent({}, {...file, filename: component.name, size: component.size}, true) + const ev = await attachmentToEvent({}, { + filename: component.name, + content_type: file.content_type, + size: component.size, + url: file.url, + height: file.height, + width: file.width, + }, true) stack.msb.addLine(ev.body, ev.formatted_body) } else if (component.type === DiscordTypes.ComponentType.MediaGallery) {