Don't delete our reaction on Discord unless we have 0 of that reaction coming from Matrix #85

Open
ellie wants to merge 8 commits from ellie/out-of-your-element:ellie-fix-reacts into main
Showing only changes of commit e21cb15c11 - Show all commits

View file

@ -45,9 +45,12 @@ async function removeReaction(event) {
const row = from("reaction").join("message_room", "message_id").join("historical_channel_room", "historical_room_index")
.select("reference_channel_id", "message_id", "encoded_emoji").where({hashed_event_id: hash}).get()
if (!row) return
// See how many Matrix-side reactions there are, and delete if it's the last one
const numberOfReactions = from("reaction").selectUnsafe("count(*)").where({message_id: row.message_id, encoded_emoji: row.encoded_emoji}).prepare().pluck().get()
if (numberOfReactions === 1) {
await discord.snow.channel.deleteReactionSelf(row.reference_channel_id, row.message_id, row.encoded_emoji)
}
db.prepare("DELETE FROM reaction WHERE hashed_event_id = ?").run(hash)
const remainingReactions = db.prepare("SELECT count(*) as count FROM REACTION WHERE message_id = ? AND encoded_emoji = ?").pluck().get(row.message_id, row.encoded_emoji) // see if we have any remaining Matrix-side reactions
if (remainingReactions == 0) await discord.snow.channel.deleteReactionSelf(row.reference_channel_id, row.message_id, row.encoded_emoji)
}
/**