Full code coverage for lottie sticker

This commit is contained in:
Cadence Ember 2024-01-19 12:38:25 +13:00
parent d02f86b342
commit f3b7fcd1a3
2 changed files with 24 additions and 23 deletions

View file

@ -497,8 +497,8 @@ async function messageToEvent(message, guild, options = {}, di) {
if (message.sticker_items) { if (message.sticker_items) {
const stickerEvents = await Promise.all(message.sticker_items.map(async stickerItem => { const stickerEvents = await Promise.all(message.sticker_items.map(async stickerItem => {
const format = file.stickerFormat.get(stickerItem.format_type) const format = file.stickerFormat.get(stickerItem.format_type)
assert(format?.mime)
if (format?.mime === "lottie") { if (format?.mime === "lottie") {
try {
const {mxc_url, info} = await lottie.convert(stickerItem) const {mxc_url, info} = await lottie.convert(stickerItem)
return { return {
$type: "m.sticker", $type: "m.sticker",
@ -507,15 +507,7 @@ async function messageToEvent(message, guild, options = {}, di) {
info, info,
url: mxc_url url: mxc_url
} }
} catch (e) { } else {
return {
$type: "m.room.message",
"m.mentions": mentions,
msgtype: "m.notice",
body: `Failed to convert Lottie sticker:\n${e.toString()}\n${e.stack}`
}
}
} else if (format?.mime) {
let body = stickerItem.name let body = stickerItem.name
const sticker = guild.stickers.find(sticker => sticker.id === stickerItem.id) const sticker = guild.stickers.find(sticker => sticker.id === stickerItem.id)
if (sticker && sticker.description) body += ` - ${sticker.description}` if (sticker && sticker.description) body += ` - ${sticker.description}`
@ -529,12 +521,6 @@ async function messageToEvent(message, guild, options = {}, di) {
url: await file.uploadDiscordFileToMxc(file.sticker(stickerItem)) url: await file.uploadDiscordFileToMxc(file.sticker(stickerItem))
} }
} }
return {
$type: "m.room.message",
"m.mentions": mentions,
msgtype: "m.notice",
body: `Unsupported sticker format ${format?.mime}. Name: ${stickerItem.name}`
}
})) }))
events.push(...stickerEvents) events.push(...stickerEvents)
} }

View file

@ -224,6 +224,21 @@ test("message2event: stickers", async t => {
}]) }])
}) })
test("message2event: lottie sticker", async t => {
const events = await messageToEvent(data.message.lottie_sticker, data.guild.general, {})
t.deepEqual(events, [{
$type: "m.sticker",
"m.mentions": {},
body: "8",
info: {
mimetype: "image/png",
w: 160,
h: 160
},
url: "mxc://cadence.moe/ZtvvVbwMIdUZeovWVyGVFCeR"
}])
})
test("message2event: skull webp attachment with content", async t => { test("message2event: skull webp attachment with content", async t => {
const events = await messageToEvent(data.message.skull_webp_attachment_with_content, data.guild.general, {}) const events = await messageToEvent(data.message.skull_webp_attachment_with_content, data.guild.general, {})
t.deepEqual(events, [{ t.deepEqual(events, [{