From a5518e562fda217dc2f898ff90e0b34999402f0f Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Wed, 28 Aug 2024 12:10:59 +1200 Subject: [PATCH] Fix reading property that was always missing --- m2d/converters/event-to-message.js | 7 +++--- m2d/converters/event-to-message.test.js | 30 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/m2d/converters/event-to-message.js b/m2d/converters/event-to-message.js index 2984e8e..6b762b4 100644 --- a/m2d/converters/event-to-message.js +++ b/m2d/converters/event-to-message.js @@ -206,11 +206,10 @@ function getCodeContent(preCode) { */ function convertEmoji(mxcUrl, nameForGuess, allowSpriteSheetIndicator, allowLink) { // Get the known emoji from the database. - let row - if (mxcUrl) row = select("emoji", ["emoji_id", "name", "animated"], {mxc_url: mxcUrl}).get() + if (mxcUrl) var row = select("emoji", ["emoji_id", "name", "animated"], {mxc_url: mxcUrl}).get() // Now we have to search all servers to see if we're able to send this emoji. if (row) { - const found = [...discord.guilds.values()].find(g => g.emojis.find(e => e.id === row.id)) + const found = [...discord.guilds.values()].find(g => g.emojis.find(e => e.id === row?.emoji_id)) if (!found) row = null } // Or, if we don't have an emoji right now, we search for the name instead. @@ -220,7 +219,7 @@ function convertEmoji(mxcUrl, nameForGuess, allowSpriteSheetIndicator, allowLink /** @type {{name: string, id: string, animated: number}[]} */ // @ts-ignore const emojis = guild.emojis - const found = emojis.find(e => e.id === row?.id || e.name?.toLowerCase() === nameForGuessLower) + const found = emojis.find(e => e.name?.toLowerCase() === nameForGuessLower) if (found) { row = { animated: found.animated, diff --git a/m2d/converters/event-to-message.test.js b/m2d/converters/event-to-message.test.js index b404e59..a802d28 100644 --- a/m2d/converters/event-to-message.test.js +++ b/m2d/converters/event-to-message.test.js @@ -3794,6 +3794,36 @@ test("event2message: static emojis work", async t => { ) }) +test("event2message: emojis in other servers are reused if they have the same title text", async t => { + t.deepEqual( + await eventToMessage({ + type: "m.room.message", + sender: "@cadence:cadence.moe", + content: { + msgtype: "m.text", + body: ":hippo:", + format: "org.matrix.custom.html", + formatted_body: '\":hippo:\"' + }, + event_id: "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU", + room_id: "!CzvdIdUQXgUjDVKxeU:cadence.moe" + }), + { + ensureJoined: [], + messagesToDelete: [], + messagesToEdit: [], + messagesToSend: [{ + username: "cadence [they]", + content: "<:hippo:230201364309868544>", + avatar_url: "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU", + allowed_mentions: { + parse: ["users", "roles"] + } + }] + } + ) +}) + test("event2message: animated emojis work", async t => { t.deepEqual( await eventToMessage({