mirror of
https://gitdab.com/cadence/out-of-your-element.git
synced 2025-09-11 04:33:02 +02:00
Use kstate for d->m pins updates
This commit is contained in:
parent
0c1b4c5e8e
commit
6e55061760
8 changed files with 50 additions and 42 deletions
|
@ -6,6 +6,8 @@ const {discord, sync, db} = passthrough
|
|||
const pinsToList = sync.require("../converters/pins-to-list")
|
||||
/** @type {import("../../matrix/api")} */
|
||||
const api = sync.require("../../matrix/api")
|
||||
/** @type {import("../../matrix/kstate")} */
|
||||
const ks = sync.require("../../matrix/kstate")
|
||||
|
||||
/**
|
||||
* @template {string | null | undefined} T
|
||||
|
@ -23,11 +25,13 @@ function convertTimestamp(timestamp) {
|
|||
* @param {number?} convertedTimestamp
|
||||
*/
|
||||
async function updatePins(channelID, roomID, convertedTimestamp) {
|
||||
const pins = await discord.snow.channel.getChannelPinnedMessages(channelID)
|
||||
const eventIDs = pinsToList.pinsToList(pins)
|
||||
await api.sendState(roomID, "m.room.pinned_events", "", {
|
||||
pinned: eventIDs
|
||||
})
|
||||
const discordPins = await discord.snow.channel.getChannelPinnedMessages(channelID)
|
||||
const pinned = pinsToList.pinsToList(discordPins)
|
||||
|
||||
const kstate = await ks.roomToKState(roomID)
|
||||
const diff = ks.diffKState(kstate, {"m.room.pinned_events/": {pinned}})
|
||||
await ks.applyKStateDiffToRoom(roomID, diff)
|
||||
|
||||
db.prepare("UPDATE channel_room SET last_bridged_pin_timestamp = ? WHERE channel_id = ?").run(convertedTimestamp || 0, channelID)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue