Sync pins back from Matrix to Discord

This commit is contained in:
Cadence Ember
2025-01-07 12:24:03 +13:00
parent 4c62124cee
commit 06b6a63ee3
6 changed files with 87 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
// @ts-check
const {sync, from, discord} = require("../../passthrough")
/** @type {import("../converters/diff-pins")} */
const diffPins = sync.require("../converters/diff-pins")
/**
* @param {string[]} pins
* @param {string[]} prev
*/
async function updatePins(pins, prev) {
const diff = diffPins.diffPins(pins, prev)
for (const [event_id, added] of diff) {
const row = from("event_message").join("message_channel", "message_id").where({event_id}).select("channel_id", "message_id").get()
if (!row) continue
if (added) {
discord.snow.channel.addChannelPinnedMessage(row.channel_id, row.message_id, "Message pinned on Matrix")
} else {
discord.snow.channel.removeChannelPinnedMessage(row.channel_id, row.message_id, "Message unpinned on Matrix")
}
}
}
module.exports.updatePins = updatePins