Fix reading property that was always missing

This commit is contained in:
Cadence Ember 2024-08-28 12:10:59 +12:00
parent 5af7d6bf42
commit a5518e562f
2 changed files with 33 additions and 4 deletions

View file

@ -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,

View file

@ -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: '<img data-mx-emoticon height=\"32\" src=\"mxc://cadence.moe/123456\" title=\":hippo:\" alt=\":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({