From c9c22cdf40e100a335037fae93b31275631cda52 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Tue, 29 Aug 2023 17:08:00 +1200 Subject: [PATCH] d->m bridge other attachments as m.file --- d2m/converters/message-to-event.js | 26 ++++++++++++++++++++++++-- notes.md | 2 +- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/d2m/converters/message-to-event.js b/d2m/converters/message-to-event.js index d8b85200..cfdcd12d 100644 --- a/d2m/converters/message-to-event.js +++ b/d2m/converters/message-to-event.js @@ -289,12 +289,34 @@ async function messageToEvent(message, guild, options = {}, di) { size: attachment.size } } + } else if (attachment.content_type?.startsWith("audio/")) { + return { + $type: "m.room.message", + "m.mentions": mentions, + msgtype: "m.audio", + url: await file.uploadDiscordFileToMxc(attachment.url), + external_url: attachment.url, + body: attachment.description || attachment.filename, + filename: attachment.filename, + info: { + mimetype: attachment.content_type, + size: attachment.size, + duration: attachment.duration_secs ? attachment.duration_secs * 1000 : undefined + } + } } else { return { $type: "m.room.message", "m.mentions": mentions, - msgtype: "m.text", - body: `Unsupported attachment:\n${JSON.stringify(attachment, null, 2)}\n${attachment.url}` + msgtype: "m.file", + url: await file.uploadDiscordFileToMxc(attachment.url), + external_url: attachment.url, + body: attachment.filename, + // TODO: filename: attachment.filename and then use body as the caption + info: { + mimetype: attachment.content_type, + size: attachment.size + } } } })) diff --git a/notes.md b/notes.md index e7017606..0b6b0888 100644 --- a/notes.md +++ b/notes.md @@ -3,7 +3,7 @@ ## Known issues - m->d attachments do not work -- d->m support the rest of the attachments by reading the matrix spec instead of the current approach of whitelisting mime types +- m->d replying to a message that used a blockquote should avoid using the blockquote contents as the preview - d->m emojis do not work at all (inline chat, single emoji size, reactions, bridged state) - m->d code blocks have slightly too much spacing - m->d some reactions don't work because of the variation selector