mirror of
https://gitdab.com/cadence/out-of-your-element.git
synced 2025-09-11 04:33:02 +02:00
d->m: preserve unknown messages when syncing pins
This commit is contained in:
parent
2a6284968f
commit
8d4d505ab9
3 changed files with 67 additions and 5 deletions
|
@ -4,16 +4,28 @@ const {select} = require("../../passthrough")
|
|||
|
||||
/**
|
||||
* @param {import("discord-api-types/v10").RESTGetAPIChannelPinsResult} pins
|
||||
* @param {{"m.room.pinned_events/"?: {pinned?: string[]}}} kstate
|
||||
*/
|
||||
function pinsToList(pins) {
|
||||
function pinsToList(pins, kstate) {
|
||||
let alreadyPinned = kstate["m.room.pinned_events/"]?.pinned || []
|
||||
|
||||
// If any of the already pinned messages are bridged messages then remove them from the already pinned list.
|
||||
// * If a bridged message is still pinned then it'll be added back in the next step.
|
||||
// * If a bridged message was unpinned from Discord-side then it'll be unpinned from our side due to this step.
|
||||
// * Matrix-only unbridged messages that are pinned will remain pinned.
|
||||
alreadyPinned = alreadyPinned.filter(event_id => {
|
||||
const messageID = select("event_message", "message_id", {event_id}).pluck().get()
|
||||
return !messageID || pins.find(m => m.id === messageID) // if it is bridged then remove it from the filter
|
||||
})
|
||||
|
||||
/** @type {string[]} */
|
||||
const result = []
|
||||
for (const message of pins) {
|
||||
const eventID = select("event_message", "event_id", {message_id: message.id, part: 0}).pluck().get()
|
||||
if (eventID) result.push(eventID)
|
||||
if (eventID && !alreadyPinned.includes(eventID)) result.push(eventID)
|
||||
}
|
||||
result.reverse()
|
||||
return result
|
||||
return alreadyPinned.concat(result)
|
||||
}
|
||||
|
||||
module.exports.pinsToList = pinsToList
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue