Fix m->d then d->m reactions not merging
This commit is contained in:
@@ -25,7 +25,7 @@ async function addReaction(data) {
|
||||
if (!parentID) return // Nothing can be done if the parent message was never bridged.
|
||||
assert.equal(typeof parentID, "string")
|
||||
|
||||
const key = await emojiToKey.emojiToKey(data.emoji)
|
||||
const key = await emojiToKey.emojiToKey(data.emoji, data.message_id)
|
||||
const shortcode = key.startsWith("mxc://") ? `:${data.emoji.name}:` : undefined
|
||||
|
||||
const roomID = await createRoom.ensureRoom(data.channel_id)
|
||||
|
||||
@@ -43,7 +43,7 @@ async function removeSomeReactions(data) {
|
||||
* @param {Ty.Event.Outer<Ty.Event.M_Reaction>[]} reactions
|
||||
*/
|
||||
async function removeReaction(data, reactions) {
|
||||
const key = await emojiToKey.emojiToKey(data.emoji)
|
||||
const key = await emojiToKey.emojiToKey(data.emoji, data.message_id)
|
||||
return converter.removeReaction(data, reactions, key)
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ async function removeReaction(data, reactions) {
|
||||
* @param {Ty.Event.Outer<Ty.Event.M_Reaction>[]} reactions
|
||||
*/
|
||||
async function removeEmojiReaction(data, reactions) {
|
||||
const key = await emojiToKey.emojiToKey(data.emoji)
|
||||
const key = await emojiToKey.emojiToKey(data.emoji, data.message_id)
|
||||
const discordPreferredEncoding = await emoji.encodeEmoji(key, undefined)
|
||||
db.prepare("DELETE FROM reaction WHERE message_id = ? AND encoded_emoji = ?").run(data.message_id, discordPreferredEncoding)
|
||||
|
||||
|
||||
@@ -8,9 +8,10 @@ const file = sync.require("../../matrix/file")
|
||||
|
||||
/**
|
||||
* @param {import("discord-api-types/v10").APIEmoji} emoji
|
||||
* @param {string} message_id
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
async function emojiToKey(emoji) {
|
||||
async function emojiToKey(emoji, message_id) {
|
||||
let key
|
||||
if (emoji.id) {
|
||||
// Custom emoji
|
||||
@@ -30,7 +31,10 @@ async function emojiToKey(emoji) {
|
||||
// Default emoji
|
||||
const name = emoji.name
|
||||
assert(name)
|
||||
key = name
|
||||
// If the reaction was used on Matrix already, it might be using a different arrangement of Variation Selector 16 characters.
|
||||
// We'll use the same arrangement that was originally used, otherwise a duplicate of the emoji will appear as a separate reaction.
|
||||
const originalEncoding = select("reaction", "original_encoding", {message_id, encoded_emoji: encodeURIComponent(name)}).pluck().get()
|
||||
key = originalEncoding || name
|
||||
}
|
||||
return key
|
||||
}
|
||||
|
||||
@@ -401,7 +401,7 @@ async function messageToEvent(message, guild, options = {}, di) {
|
||||
const id = match[3]
|
||||
const name = match[2]
|
||||
const animated = !!match[1]
|
||||
return emojiToKey.emojiToKey({id, name, animated}) // Register the custom emoji if needed
|
||||
return emojiToKey.emojiToKey({id, name, animated}, message.id) // Register the custom emoji if needed
|
||||
}))
|
||||
|
||||
async function transformParsedVia(parsed) {
|
||||
|
||||
Reference in New Issue
Block a user