Bridge the shortcode as part of reactions

This commit is contained in:
Cadence Ember 2023-09-25 20:18:57 +13:00
parent 4f807159ba
commit a396e6f596
3 changed files with 13 additions and 8 deletions

View file

@ -50,7 +50,8 @@ async function addReaction(data) {
rel_type: "m.annotation",
event_id: parentID,
key
}
},
shortcode: `:${data.emoji.name}:`
}, senderMxid)
return eventID
}

View file

@ -21,16 +21,19 @@ async function addReaction(event) {
let discordPreferredEncoding
if (emoji.startsWith("mxc://")) {
// Custom emoji
const row = select("emoji", ["id", "name"], "WHERE mxc_url = ?").get(emoji)
if (row) {
// Great, we know exactly what this emoji is!
discordPreferredEncoding = encodeURIComponent(`${row.name}:${row.id}`)
} else {
let row = select("emoji", ["id", "name"], "WHERE mxc_url = ?").get(emoji)
if (!row && event.content.shortcode) {
// Use the name to try to find a known emoji with the same name.
const name = event.content.shortcode.replace(/^:|:$/g, "")
row = select("emoji", ["id", "name"], "WHERE name = ?").get(name)
}
if (!row) {
// We don't have this emoji and there's no realistic way to just-in-time upload a new emoji somewhere.
// We can't try using a known emoji with the same name because we don't even know what the name is. We only have the mxc url.
// Sucks!
return
}
// Cool, we got an exact or a candidate emoji.
discordPreferredEncoding = encodeURIComponent(`${row.name}:${row.id}`)
} else {
// Default emoji
// https://github.com/discord/discord-api-docs/issues/2723#issuecomment-807022205 ????????????

3
types.d.ts vendored
View file

@ -171,7 +171,8 @@ export namespace Event {
rel_type: "m.annotation"
event_id: string // the event that was reacted to
key: string // the unicode emoji, mxc uri, or reaction text
}
},
"shortcode"?: string // starts and ends with colons
}
export type Outer_M_Room_Redaction = Outer<{