forked from cadence/out-of-your-element
upload spoiler attachments as spoilers
This commit is contained in:
parent
6a04f3f798
commit
a1be84cb60
3 changed files with 62 additions and 1 deletions
|
@ -247,8 +247,19 @@ async function messageToEvent(message, guild, options = {}, di) {
|
|||
: attachment.content_type?.startsWith("text/") ? "📝"
|
||||
: 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_")) {
|
||||
return {
|
||||
$type: "m.room.message",
|
||||
"m.mentions": mentions,
|
||||
msgtype: "m.text",
|
||||
body: `${emoji} Uploaded SPOILER file: ${attachment.url} (${pb(attachment.size)})`,
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: `<blockquote>${emoji} Uploaded SPOILER file: <span data-mx-spoiler><a href="${attachment.url}">View</a></span> (${pb(attachment.size)})</blockquote>`
|
||||
}
|
||||
}
|
||||
// for large files, always link them instead of uploading so I don't use up all the space in the content repo
|
||||
if (attachment.size > reg.ooye.max_file_size) {
|
||||
else if (attachment.size > reg.ooye.max_file_size) {
|
||||
return {
|
||||
$type: "m.room.message",
|
||||
"m.mentions": mentions,
|
||||
|
|
|
@ -104,6 +104,18 @@ test("message2event: attachment with no content", async t => {
|
|||
}])
|
||||
})
|
||||
|
||||
test("message2event: spoiler attachment", async t => {
|
||||
const events = await messageToEvent(data.message.spoiler_attachment, data.guild.general, {})
|
||||
t.deepEqual(events, [{
|
||||
$type: "m.room.message",
|
||||
"m.mentions": {},
|
||||
msgtype: "m.text",
|
||||
body: "📄 Uploaded SPOILER file: https://cdn.discordapp.com/attachments/1100319550446252084/1147465564307079258/SPOILER_69-GNDP-CADENCE.nfs.gci (74 KB)",
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: "<blockquote>📄 Uploaded SPOILER file: <span data-mx-spoiler><a href=\"https://cdn.discordapp.com/attachments/1100319550446252084/1147465564307079258/SPOILER_69-GNDP-CADENCE.nfs.gci\">View</a></span> (74 KB)</blockquote>"
|
||||
}])
|
||||
})
|
||||
|
||||
test("message2event: stickers", async t => {
|
||||
const events = await messageToEvent(data.message.sticker, data.guild.general, {})
|
||||
t.deepEqual(events, [{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue