forked from cadence/out-of-your-element
Backfill missed pins and pins from the past
This commit is contained in:
parent
ed7404ea19
commit
8987107685
9 changed files with 147 additions and 13 deletions
|
@ -1,22 +1,37 @@
|
|||
// @ts-check
|
||||
|
||||
const passthrough = require("../../passthrough")
|
||||
const {discord, sync} = passthrough
|
||||
const {discord, sync, db} = passthrough
|
||||
/** @type {import("../converters/pins-to-list")} */
|
||||
const pinsToList = sync.require("../converters/pins-to-list")
|
||||
/** @type {import("../../matrix/api")} */
|
||||
const api = sync.require("../../matrix/api")
|
||||
|
||||
/**
|
||||
* @param {string} channelID
|
||||
* @param {string} roomID
|
||||
* @template {string | null | undefined} T
|
||||
* @param {T} timestamp
|
||||
* @returns {T extends string ? number : null}
|
||||
*/
|
||||
async function updatePins(channelID, roomID) {
|
||||
const pins = await discord.snow.channel.getChannelPinnedMessages(channelID)
|
||||
const eventIDs = pinsToList.pinsToList(pins)
|
||||
await api.sendState(roomID, "m.room.pinned_events", "", {
|
||||
pinned: eventIDs
|
||||
})
|
||||
function convertTimestamp(timestamp) {
|
||||
// @ts-ignore
|
||||
return typeof timestamp === "string" ? Math.floor(new Date(timestamp).getTime() / 1000) : null
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} channelID
|
||||
* @param {string} roomID
|
||||
* @param {number?} convertedTimestamp
|
||||
*/
|
||||
async function updatePins(channelID, roomID, convertedTimestamp) {
|
||||
const pins = await discord.snow.channel.getChannelPinnedMessages(channelID)
|
||||
const eventIDs = pinsToList.pinsToList(pins)
|
||||
if (pins.length === eventIDs.length || eventIDs.length) {
|
||||
await api.sendState(roomID, "m.room.pinned_events", "", {
|
||||
pinned: eventIDs
|
||||
})
|
||||
}
|
||||
db.prepare("UPDATE channel_room SET last_bridged_pin_timestamp = ? WHERE channel_id = ?").run(convertedTimestamp || 0, channelID)
|
||||
}
|
||||
|
||||
module.exports.convertTimestamp = convertTimestamp
|
||||
module.exports.updatePins = updatePins
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue