forked from cadence/out-of-your-element
make removing single reactions work correctly
This commit is contained in:
parent
a396e6f596
commit
6dcf3a383a
7 changed files with 67 additions and 30 deletions
|
@ -10,8 +10,9 @@ const api = sync.require("../../matrix/api")
|
|||
const registerUser = sync.require("./register-user")
|
||||
/** @type {import("../actions/create-room")} */
|
||||
const createRoom = sync.require("../actions/create-room")
|
||||
/** @type {import("../../matrix/file")} */
|
||||
const file = sync.require("../../matrix/file")
|
||||
/** @type {import("../converters/emoji-to-key")} */
|
||||
const emojiToKey = sync.require("../converters/emoji-to-key")
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("discord-api-types/v10").GatewayMessageReactionAddDispatchData} data
|
||||
|
@ -24,24 +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")
|
||||
|
||||
let key
|
||||
if (data.emoji.id) {
|
||||
// Custom emoji
|
||||
const mxc = select("emoji", "mxc_url", "WHERE id = ?").pluck().get(data.emoji.id)
|
||||
if (mxc) {
|
||||
// The custom emoji is registered and we should send it
|
||||
key = mxc
|
||||
} else {
|
||||
// The custom emoji is not registered. We will register it and then add it.
|
||||
const mxc = await file.uploadDiscordFileToMxc(file.emoji(data.emoji.id, data.emoji.animated))
|
||||
db.prepare("INSERT OR IGNORE INTO emoji (id, name, animated, mxc_url) VALUES (?, ?, ?, ?)").run(data.emoji.id, data.emoji.name, +!!data.emoji.animated, mxc)
|
||||
key = mxc
|
||||
// TODO: what happens if the matrix user also tries adding this reaction? the bridge bot isn't able to use that emoji...
|
||||
}
|
||||
} else {
|
||||
// Default emoji
|
||||
key = data.emoji.name
|
||||
}
|
||||
const key = await emojiToKey.emojiToKey(data.emoji)
|
||||
|
||||
const roomID = await createRoom.ensureRoom(data.channel_id)
|
||||
const senderMxid = await registerUser.ensureSimJoined(user, roomID)
|
||||
|
|
|
@ -7,12 +7,8 @@ const passthrough = require("../../passthrough")
|
|||
const {discord, sync, db, select} = passthrough
|
||||
/** @type {import("../../matrix/api")} */
|
||||
const api = sync.require("../../matrix/api")
|
||||
/** @type {import("./register-user")} */
|
||||
const registerUser = sync.require("./register-user")
|
||||
/** @type {import("../actions/create-room")} */
|
||||
const createRoom = sync.require("../actions/create-room")
|
||||
/** @type {import("../../matrix/file")} */
|
||||
const file = sync.require("../../matrix/file")
|
||||
/** @type {import("../converters/emoji-to-key")} */
|
||||
const emojiToKey = sync.require("../converters/emoji-to-key")
|
||||
|
||||
/**
|
||||
* @param {import("discord-api-types/v10").GatewayMessageReactionRemoveDispatchData} data
|
||||
|
@ -27,10 +23,11 @@ async function removeReaction(data) {
|
|||
|
||||
/** @type {Ty.Pagination<Ty.Event.Outer<Ty.Event.M_Reaction>>} */
|
||||
const relations = await api.getRelations(roomID, eventIDForMessage, "m.annotation")
|
||||
const eventIDForReaction = relations.chunk.find(e => e.sender === mxid && e.content["m.relates_to"].key === data.emoji) // TODO: get the key from the emoji
|
||||
const key = await emojiToKey.emojiToKey(data.emoji)
|
||||
const eventIDForReaction = relations.chunk.find(e => e.sender === mxid && e.content["m.relates_to"].key === key)
|
||||
if (!eventIDForReaction) return
|
||||
|
||||
await api.redactEvent(roomID, eventIDForReaction, mxid)
|
||||
await api.redactEvent(roomID, eventIDForReaction.event_id, mxid)
|
||||
}
|
||||
|
||||
module.exports.removeReaction = removeReaction
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue