Compare commits
No commits in common. "ad1aa2c0f663f0936bb95e123cf5ccb0369d808a" and "fb18c0fe0b311baea311fb373a8921b14ed5b26a" have entirely different histories.
ad1aa2c0f6
...
fb18c0fe0b
11 changed files with 46 additions and 205 deletions
|
@ -39,6 +39,26 @@ const DEFAULT_PRIVACY_LEVEL = 0
|
||||||
/** @type {Map<string, Promise<string>>} channel ID -> Promise<room ID> */
|
/** @type {Map<string, Promise<string>>} channel ID -> Promise<room ID> */
|
||||||
const inflightRoomCreate = new Map()
|
const inflightRoomCreate = new Map()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Async because it gets all room state from the homeserver.
|
||||||
|
* @param {string} roomID
|
||||||
|
*/
|
||||||
|
async function roomToKState(roomID) {
|
||||||
|
const root = await api.getAllState(roomID)
|
||||||
|
return ks.stateToKState(root)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} roomID
|
||||||
|
* @param {any} kstate
|
||||||
|
*/
|
||||||
|
async function applyKStateDiffToRoom(roomID, kstate) {
|
||||||
|
const events = await ks.kstateToState(kstate)
|
||||||
|
return Promise.all(events.map(({type, state_key, content}) =>
|
||||||
|
api.sendState(roomID, type, state_key, content)
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {{id: string, name: string, topic?: string?, type: number, parent_id?: string?}} channel
|
* @param {{id: string, name: string, topic?: string?, type: number, parent_id?: string?}} channel
|
||||||
* @param {{id: string}} guild
|
* @param {{id: string}} guild
|
||||||
|
@ -233,9 +253,9 @@ async function postApplyPowerLevels(kstate, callback) {
|
||||||
|
|
||||||
// Now *really* apply the power level overrides on top of what Synapse *really* set
|
// Now *really* apply the power level overrides on top of what Synapse *really* set
|
||||||
if (powerLevelContent) {
|
if (powerLevelContent) {
|
||||||
const newRoomKState = await ks.roomToKState(roomID)
|
const newRoomKState = await roomToKState(roomID)
|
||||||
const newRoomPowerLevelsDiff = ks.diffKState(newRoomKState, {"m.room.power_levels/": powerLevelContent})
|
const newRoomPowerLevelsDiff = ks.diffKState(newRoomKState, {"m.room.power_levels/": powerLevelContent})
|
||||||
await ks.applyKStateDiffToRoom(roomID, newRoomPowerLevelsDiff)
|
await applyKStateDiffToRoom(roomID, newRoomPowerLevelsDiff)
|
||||||
}
|
}
|
||||||
|
|
||||||
return roomID
|
return roomID
|
||||||
|
@ -364,7 +384,7 @@ async function _syncRoom(channelID, shouldActuallySync) {
|
||||||
const {spaceID, channelKState} = await channelToKState(channel, guild, {api}) // calling this in both branches because we don't want to calculate this if not syncing
|
const {spaceID, channelKState} = await channelToKState(channel, guild, {api}) // calling this in both branches because we don't want to calculate this if not syncing
|
||||||
|
|
||||||
// sync channel state to room
|
// sync channel state to room
|
||||||
const roomKState = await ks.roomToKState(roomID)
|
const roomKState = await roomToKState(roomID)
|
||||||
if (+roomKState["m.room.create/"].room_version <= 8) {
|
if (+roomKState["m.room.create/"].room_version <= 8) {
|
||||||
// join_rule `restricted` is not available in room version < 8 and not working properly in version == 8
|
// join_rule `restricted` is not available in room version < 8 and not working properly in version == 8
|
||||||
// read more: https://spec.matrix.org/v1.8/rooms/v9/
|
// read more: https://spec.matrix.org/v1.8/rooms/v9/
|
||||||
|
@ -372,7 +392,7 @@ async function _syncRoom(channelID, shouldActuallySync) {
|
||||||
channelKState["m.room.join_rules/"] = {join_rule: "public"}
|
channelKState["m.room.join_rules/"] = {join_rule: "public"}
|
||||||
}
|
}
|
||||||
const roomDiff = ks.diffKState(roomKState, channelKState)
|
const roomDiff = ks.diffKState(roomKState, channelKState)
|
||||||
const roomApply = ks.applyKStateDiffToRoom(roomID, roomDiff)
|
const roomApply = applyKStateDiffToRoom(roomID, roomDiff)
|
||||||
db.prepare("UPDATE channel_room SET name = ? WHERE room_id = ?").run(channel.name, roomID)
|
db.prepare("UPDATE channel_room SET name = ? WHERE room_id = ?").run(channel.name, roomID)
|
||||||
|
|
||||||
// sync room as space member
|
// sync room as space member
|
||||||
|
@ -442,7 +462,7 @@ async function unbridgeDeletedChannel(channel, guildID) {
|
||||||
* @returns {Promise<string[]>}
|
* @returns {Promise<string[]>}
|
||||||
*/
|
*/
|
||||||
async function _syncSpaceMember(channel, spaceID, roomID) {
|
async function _syncSpaceMember(channel, spaceID, roomID) {
|
||||||
const spaceKState = await ks.roomToKState(spaceID)
|
const spaceKState = await roomToKState(spaceID)
|
||||||
let spaceEventContent = {}
|
let spaceEventContent = {}
|
||||||
if (
|
if (
|
||||||
channel.type !== DiscordTypes.ChannelType.PrivateThread // private threads do not belong in the space (don't offer people something they can't join)
|
channel.type !== DiscordTypes.ChannelType.PrivateThread // private threads do not belong in the space (don't offer people something they can't join)
|
||||||
|
@ -455,7 +475,7 @@ async function _syncSpaceMember(channel, spaceID, roomID) {
|
||||||
const spaceDiff = ks.diffKState(spaceKState, {
|
const spaceDiff = ks.diffKState(spaceKState, {
|
||||||
[`m.space.child/${roomID}`]: spaceEventContent
|
[`m.space.child/${roomID}`]: spaceEventContent
|
||||||
})
|
})
|
||||||
return ks.applyKStateDiffToRoom(spaceID, spaceDiff)
|
return applyKStateDiffToRoom(spaceID, spaceDiff)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createAllForGuild(guildID) {
|
async function createAllForGuild(guildID) {
|
||||||
|
@ -478,6 +498,8 @@ module.exports.ensureRoom = ensureRoom
|
||||||
module.exports.syncRoom = syncRoom
|
module.exports.syncRoom = syncRoom
|
||||||
module.exports.createAllForGuild = createAllForGuild
|
module.exports.createAllForGuild = createAllForGuild
|
||||||
module.exports.channelToKState = channelToKState
|
module.exports.channelToKState = channelToKState
|
||||||
|
module.exports.roomToKState = roomToKState
|
||||||
|
module.exports.applyKStateDiffToRoom = applyKStateDiffToRoom
|
||||||
module.exports.postApplyPowerLevels = postApplyPowerLevels
|
module.exports.postApplyPowerLevels = postApplyPowerLevels
|
||||||
module.exports._convertNameAndTopic = convertNameAndTopic
|
module.exports._convertNameAndTopic = convertNameAndTopic
|
||||||
module.exports._unbridgeRoom = _unbridgeRoom
|
module.exports._unbridgeRoom = _unbridgeRoom
|
||||||
|
|
|
@ -116,9 +116,9 @@ async function _syncSpace(guild, shouldActuallySync) {
|
||||||
const guildKState = await guildToKState(guild, privacy_level) // calling this in both branches because we don't want to calculate this if not syncing
|
const guildKState = await guildToKState(guild, privacy_level) // calling this in both branches because we don't want to calculate this if not syncing
|
||||||
|
|
||||||
// sync guild state to space
|
// sync guild state to space
|
||||||
const spaceKState = await ks.roomToKState(spaceID)
|
const spaceKState = await createRoom.roomToKState(spaceID)
|
||||||
const spaceDiff = ks.diffKState(spaceKState, guildKState)
|
const spaceDiff = ks.diffKState(spaceKState, guildKState)
|
||||||
await ks.applyKStateDiffToRoom(spaceID, spaceDiff)
|
await createRoom.applyKStateDiffToRoom(spaceID, spaceDiff)
|
||||||
|
|
||||||
// guild icon was changed, so room avatars need to be updated as well as the space ones
|
// guild icon was changed, so room avatars need to be updated as well as the space ones
|
||||||
// doing it this way rather than calling syncRoom for great efficiency gains
|
// doing it this way rather than calling syncRoom for great efficiency gains
|
||||||
|
@ -183,9 +183,9 @@ async function syncSpaceFully(guildID) {
|
||||||
const guildKState = await guildToKState(guild, privacy_level)
|
const guildKState = await guildToKState(guild, privacy_level)
|
||||||
|
|
||||||
// sync guild state to space
|
// sync guild state to space
|
||||||
const spaceKState = await ks.roomToKState(spaceID)
|
const spaceKState = await createRoom.roomToKState(spaceID)
|
||||||
const spaceDiff = ks.diffKState(spaceKState, guildKState)
|
const spaceDiff = ks.diffKState(spaceKState, guildKState)
|
||||||
await ks.applyKStateDiffToRoom(spaceID, spaceDiff)
|
await createRoom.applyKStateDiffToRoom(spaceID, spaceDiff)
|
||||||
|
|
||||||
const childRooms = await api.getFullHierarchy(spaceID)
|
const childRooms = await api.getFullHierarchy(spaceID)
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,6 @@ const {discord, sync, db} = passthrough
|
||||||
const pinsToList = sync.require("../converters/pins-to-list")
|
const pinsToList = sync.require("../converters/pins-to-list")
|
||||||
/** @type {import("../../matrix/api")} */
|
/** @type {import("../../matrix/api")} */
|
||||||
const api = sync.require("../../matrix/api")
|
const api = sync.require("../../matrix/api")
|
||||||
/** @type {import("../../matrix/kstate")} */
|
|
||||||
const ks = sync.require("../../matrix/kstate")
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @template {string | null | undefined} T
|
* @template {string | null | undefined} T
|
||||||
|
@ -25,13 +23,13 @@ function convertTimestamp(timestamp) {
|
||||||
* @param {number?} convertedTimestamp
|
* @param {number?} convertedTimestamp
|
||||||
*/
|
*/
|
||||||
async function updatePins(channelID, roomID, convertedTimestamp) {
|
async function updatePins(channelID, roomID, convertedTimestamp) {
|
||||||
const discordPins = await discord.snow.channel.getChannelPinnedMessages(channelID)
|
const pins = await discord.snow.channel.getChannelPinnedMessages(channelID)
|
||||||
const pinned = pinsToList.pinsToList(discordPins)
|
const eventIDs = pinsToList.pinsToList(pins)
|
||||||
|
if (pins.length === eventIDs.length || eventIDs.length) {
|
||||||
const kstate = await ks.roomToKState(roomID)
|
await api.sendState(roomID, "m.room.pinned_events", "", {
|
||||||
const diff = ks.diffKState(kstate, {"m.room.pinned_events/": {pinned}})
|
pinned: eventIDs
|
||||||
await ks.applyKStateDiffToRoom(roomID, diff)
|
})
|
||||||
|
}
|
||||||
db.prepare("UPDATE channel_room SET last_bridged_pin_timestamp = ? WHERE channel_id = ?").run(convertedTimestamp || 0, channelID)
|
db.prepare("UPDATE channel_room SET last_bridged_pin_timestamp = ? WHERE channel_id = ?").run(convertedTimestamp || 0, channelID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -330,9 +330,9 @@ async function uploadEndOfMessageSpriteSheet(content, attachments, pendingFiles,
|
||||||
*/
|
*/
|
||||||
async function handleRoomOrMessageLinks(input, di) {
|
async function handleRoomOrMessageLinks(input, di) {
|
||||||
let offset = 0
|
let offset = 0
|
||||||
for (const match of [...input.matchAll(/("?https:\/\/matrix.to\/#\/((?:#|%23|!)[^"/, ?)]+)(?:\/(\$[^"/ ?)]+))?(?:\?[^",:!? )]*?)?)(">|[,<\n )]|$)/g)]) {
|
for (const match of [...input.matchAll(/("?https:\/\/matrix.to\/#\/(![^"/, ?)]+)(?:\/(\$[^"/ ?)]+))?(?:\?[^",:!? )]*?)?)(">|[,<\n )]|$)/g)]) {
|
||||||
assert(typeof match.index === "number")
|
assert(typeof match.index === "number")
|
||||||
let [_, attributeValue, roomID, eventID, endMarker] = match
|
const [_, attributeValue, roomID, eventID, endMarker] = match
|
||||||
let result
|
let result
|
||||||
|
|
||||||
const resultType = endMarker === '">' ? "html" : "plain"
|
const resultType = endMarker === '">' ? "html" : "plain"
|
||||||
|
@ -350,16 +350,6 @@ async function handleRoomOrMessageLinks(input, di) {
|
||||||
// Don't process links that are part of the reply fallback, they'll be removed entirely by turndown
|
// Don't process links that are part of the reply fallback, they'll be removed entirely by turndown
|
||||||
if (input.slice(match.index + match[0].length + offset).startsWith("In reply to")) continue
|
if (input.slice(match.index + match[0].length + offset).startsWith("In reply to")) continue
|
||||||
|
|
||||||
// Resolve room alias to room ID if needed
|
|
||||||
roomID = decodeURIComponent(roomID)
|
|
||||||
if (roomID[0] === "#") {
|
|
||||||
try {
|
|
||||||
roomID = await di.api.getAlias(roomID)
|
|
||||||
} catch (e) {
|
|
||||||
continue // Room alias is unresolvable, so it can't be converted
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const channelID = select("channel_room", "channel_id", {room_id: roomID}).pluck().get()
|
const channelID = select("channel_room", "channel_id", {room_id: roomID}).pluck().get()
|
||||||
if (!channelID) continue
|
if (!channelID) continue
|
||||||
if (!eventID) {
|
if (!eventID) {
|
||||||
|
|
|
@ -2957,133 +2957,6 @@ test("event2message: mentioning bridged rooms works (plaintext body)", async t =
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
test("event2message: mentioning bridged rooms by alias works", async t => {
|
|
||||||
let called = 0
|
|
||||||
t.deepEqual(
|
|
||||||
await eventToMessage({
|
|
||||||
content: {
|
|
||||||
msgtype: "m.text",
|
|
||||||
body: "wrong body",
|
|
||||||
format: "org.matrix.custom.html",
|
|
||||||
formatted_body: `I'm just <a href="https://matrix.to/#/%23worm-farm%3Acadence.moe?via=cadence.moe">worm-farm</a> testing channel mentions`
|
|
||||||
},
|
|
||||||
event_id: "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU",
|
|
||||||
origin_server_ts: 1688301929913,
|
|
||||||
room_id: "!kLRqKKUQXcibIMtOpl:cadence.moe",
|
|
||||||
sender: "@cadence:cadence.moe",
|
|
||||||
type: "m.room.message",
|
|
||||||
unsigned: {
|
|
||||||
age: 405299
|
|
||||||
}
|
|
||||||
}, {}, {
|
|
||||||
api: {
|
|
||||||
async getAlias(alias) {
|
|
||||||
called++
|
|
||||||
t.equal(alias, "#worm-farm:cadence.moe")
|
|
||||||
return "!BnKuBPCvyfOkhcUjEu:cadence.moe"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
{
|
|
||||||
ensureJoined: [],
|
|
||||||
messagesToDelete: [],
|
|
||||||
messagesToEdit: [],
|
|
||||||
messagesToSend: [{
|
|
||||||
username: "cadence [they]",
|
|
||||||
content: "I'm just <#1100319550446252084> testing channel mentions",
|
|
||||||
avatar_url: undefined,
|
|
||||||
allowed_mentions: {
|
|
||||||
parse: ["users", "roles"]
|
|
||||||
}
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
)
|
|
||||||
t.equal(called, 1)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("event2message: mentioning bridged rooms by alias works (plaintext body)", async t => {
|
|
||||||
let called = 0
|
|
||||||
t.deepEqual(
|
|
||||||
await eventToMessage({
|
|
||||||
content: {
|
|
||||||
msgtype: "m.text",
|
|
||||||
body: `I'm just https://matrix.to/#/#worm-farm:cadence.moe?via=cadence.moe testing channel mentions`
|
|
||||||
},
|
|
||||||
event_id: "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU",
|
|
||||||
origin_server_ts: 1688301929913,
|
|
||||||
room_id: "!kLRqKKUQXcibIMtOpl:cadence.moe",
|
|
||||||
sender: "@cadence:cadence.moe",
|
|
||||||
type: "m.room.message",
|
|
||||||
unsigned: {
|
|
||||||
age: 405299
|
|
||||||
}
|
|
||||||
}, {}, {
|
|
||||||
api: {
|
|
||||||
async getAlias(alias) {
|
|
||||||
called++
|
|
||||||
t.equal(alias, "#worm-farm:cadence.moe")
|
|
||||||
return "!BnKuBPCvyfOkhcUjEu:cadence.moe"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
{
|
|
||||||
ensureJoined: [],
|
|
||||||
messagesToDelete: [],
|
|
||||||
messagesToEdit: [],
|
|
||||||
messagesToSend: [{
|
|
||||||
username: "cadence [they]",
|
|
||||||
content: "I'm just <#1100319550446252084> testing channel mentions",
|
|
||||||
avatar_url: undefined,
|
|
||||||
allowed_mentions: {
|
|
||||||
parse: ["users", "roles"]
|
|
||||||
}
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
)
|
|
||||||
t.equal(called, 1)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("event2message: mentioning bridged rooms by alias skips the link when alias is unresolvable", async t => {
|
|
||||||
let called = 0
|
|
||||||
t.deepEqual(
|
|
||||||
await eventToMessage({
|
|
||||||
content: {
|
|
||||||
msgtype: "m.text",
|
|
||||||
body: `I'm just https://matrix.to/#/#worm-farm:cadence.moe?via=cadence.moe and https://matrix.to/#/!BnKuBPCvyfOkhcUjEu:cadence.moe?via=cadence.moe testing channel mentions`
|
|
||||||
},
|
|
||||||
event_id: "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU",
|
|
||||||
origin_server_ts: 1688301929913,
|
|
||||||
room_id: "!kLRqKKUQXcibIMtOpl:cadence.moe",
|
|
||||||
sender: "@cadence:cadence.moe",
|
|
||||||
type: "m.room.message",
|
|
||||||
unsigned: {
|
|
||||||
age: 405299
|
|
||||||
}
|
|
||||||
}, {}, {
|
|
||||||
api: {
|
|
||||||
async getAlias(alias) {
|
|
||||||
called++
|
|
||||||
throw new MatrixServerError("Alias doesn't exist or something")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
{
|
|
||||||
ensureJoined: [],
|
|
||||||
messagesToDelete: [],
|
|
||||||
messagesToEdit: [],
|
|
||||||
messagesToSend: [{
|
|
||||||
username: "cadence [they]",
|
|
||||||
content: "I'm just <https://matrix.to/#/#worm-farm:cadence.moe?via=cadence.moe> and <#1100319550446252084> testing channel mentions",
|
|
||||||
avatar_url: undefined,
|
|
||||||
allowed_mentions: {
|
|
||||||
parse: ["users", "roles"]
|
|
||||||
}
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
)
|
|
||||||
t.equal(called, 1)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("event2message: mentioning known bridged events works (plaintext body)", async t => {
|
test("event2message: mentioning known bridged events works (plaintext body)", async t => {
|
||||||
t.deepEqual(
|
t.deepEqual(
|
||||||
await eventToMessage({
|
await eventToMessage({
|
||||||
|
|
|
@ -189,7 +189,6 @@ async event => {
|
||||||
}
|
}
|
||||||
|
|
||||||
await updatePins.updatePins(pins, prev)
|
await updatePins.updatePins(pins, prev)
|
||||||
await api.ackEvent(event)
|
|
||||||
}))
|
}))
|
||||||
|
|
||||||
sync.addTemporaryListener(as, "type:m.room.member", guard("m.room.member",
|
sync.addTemporaryListener(as, "type:m.room.member", guard("m.room.member",
|
||||||
|
|
|
@ -6,7 +6,7 @@ const assert = require("assert").strict
|
||||||
const fetch = require("node-fetch").default
|
const fetch = require("node-fetch").default
|
||||||
|
|
||||||
const passthrough = require("../passthrough")
|
const passthrough = require("../passthrough")
|
||||||
const {sync} = passthrough
|
const { discord, sync, db } = passthrough
|
||||||
/** @type {import("./mreq")} */
|
/** @type {import("./mreq")} */
|
||||||
const mreq = sync.require("./mreq")
|
const mreq = sync.require("./mreq")
|
||||||
/** @type {import("./txnid")} */
|
/** @type {import("./txnid")} */
|
||||||
|
@ -367,16 +367,6 @@ async function ackEvent(event, mxid) {
|
||||||
await sendReadReceipt(event.room_id, event.event_id, mxid)
|
await sendReadReceipt(event.room_id, event.event_id, mxid)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Resolve a room alias to a room ID.
|
|
||||||
* @param {string} alias
|
|
||||||
*/
|
|
||||||
async function getAlias(alias) {
|
|
||||||
/** @type {Ty.R.ResolvedRoom} */
|
|
||||||
const root = await mreq.mreq("GET", `/client/v3/directory/room/${encodeURIComponent(alias)}`)
|
|
||||||
return root.room_id
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports.path = path
|
module.exports.path = path
|
||||||
module.exports.register = register
|
module.exports.register = register
|
||||||
module.exports.createRoom = createRoom
|
module.exports.createRoom = createRoom
|
||||||
|
@ -405,4 +395,3 @@ module.exports.ping = ping
|
||||||
module.exports.getMedia = getMedia
|
module.exports.getMedia = getMedia
|
||||||
module.exports.sendReadReceipt = sendReadReceipt
|
module.exports.sendReadReceipt = sendReadReceipt
|
||||||
module.exports.ackEvent = ackEvent
|
module.exports.ackEvent = ackEvent
|
||||||
module.exports.getAlias = getAlias
|
|
||||||
|
|
|
@ -8,8 +8,6 @@ const passthrough = require("../passthrough")
|
||||||
const {sync} = passthrough
|
const {sync} = passthrough
|
||||||
/** @type {import("./file")} */
|
/** @type {import("./file")} */
|
||||||
const file = sync.require("./file")
|
const file = sync.require("./file")
|
||||||
/** @type {import("./api")} */
|
|
||||||
const api = sync.require("./api")
|
|
||||||
|
|
||||||
/** Mutates the input. Not recursive - can only include or exclude entire state events. */
|
/** Mutates the input. Not recursive - can only include or exclude entire state events. */
|
||||||
function kstateStripConditionals(kstate) {
|
function kstateStripConditionals(kstate) {
|
||||||
|
@ -104,32 +102,8 @@ function diffKState(actual, target) {
|
||||||
return diff
|
return diff
|
||||||
}
|
}
|
||||||
|
|
||||||
/* c8 ignore start */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Async because it gets all room state from the homeserver.
|
|
||||||
* @param {string} roomID
|
|
||||||
*/
|
|
||||||
async function roomToKState(roomID) {
|
|
||||||
const root = await api.getAllState(roomID)
|
|
||||||
return stateToKState(root)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {string} roomID
|
|
||||||
* @param {any} kstate
|
|
||||||
*/
|
|
||||||
async function applyKStateDiffToRoom(roomID, kstate) {
|
|
||||||
const events = await kstateToState(kstate)
|
|
||||||
return Promise.all(events.map(({type, state_key, content}) =>
|
|
||||||
api.sendState(roomID, type, state_key, content)
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports.kstateStripConditionals = kstateStripConditionals
|
module.exports.kstateStripConditionals = kstateStripConditionals
|
||||||
module.exports.kstateUploadMxc = kstateUploadMxc
|
module.exports.kstateUploadMxc = kstateUploadMxc
|
||||||
module.exports.kstateToState = kstateToState
|
module.exports.kstateToState = kstateToState
|
||||||
module.exports.stateToKState = stateToKState
|
module.exports.stateToKState = stateToKState
|
||||||
module.exports.diffKState = diffKState
|
module.exports.diffKState = diffKState
|
||||||
module.exports.roomToKState = roomToKState
|
|
||||||
module.exports.applyKStateDiffToRoom = applyKStateDiffToRoom
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
const {db, from} = require("../passthrough")
|
const {db, from} = require("../passthrough")
|
||||||
const {reg} = require("./read-registration")
|
const {reg} = require("./read-registration")
|
||||||
const ks = require("./kstate")
|
const ks = require("./kstate")
|
||||||
|
const {applyKStateDiffToRoom, roomToKState} = require("../d2m/actions/create-room")
|
||||||
|
|
||||||
/** Apply global power level requests across ALL rooms where the member cache entry exists but the power level has not been applied yet. */
|
/** Apply global power level requests across ALL rooms where the member cache entry exists but the power level has not been applied yet. */
|
||||||
function _getAffectedRooms() {
|
function _getAffectedRooms() {
|
||||||
|
@ -22,9 +23,9 @@ async function applyPower() {
|
||||||
|
|
||||||
const rows = _getAffectedRooms()
|
const rows = _getAffectedRooms()
|
||||||
for (const row of rows) {
|
for (const row of rows) {
|
||||||
const kstate = await ks.roomToKState(row.room_id)
|
const kstate = await roomToKState(row.room_id)
|
||||||
const diff = ks.diffKState(kstate, {"m.room.power_levels/": {users: {[row.mxid]: row.power_level}}})
|
const diff = ks.diffKState(kstate, {"m.room.power_levels/": {users: {[row.mxid]: row.power_level}}})
|
||||||
await ks.applyKStateDiffToRoom(row.room_id, diff)
|
await applyKStateDiffToRoom(row.room_id, diff)
|
||||||
// There is a listener on m.room.power_levels to do this same update,
|
// There is a listener on m.room.power_levels to do this same update,
|
||||||
// but we update it here anyway since the homeserver does not always deliver the event round-trip.
|
// but we update it here anyway since the homeserver does not always deliver the event round-trip.
|
||||||
db.prepare("UPDATE member_cache SET power_level = ? WHERE room_id = ? AND mxid = ?").run(row.power_level, row.room_id, row.mxid)
|
db.prepare("UPDATE member_cache SET power_level = ? WHERE room_id = ? AND mxid = ?").run(row.power_level, row.room_id, row.mxid)
|
||||||
|
|
5
src/types.d.ts
vendored
5
src/types.d.ts
vendored
|
@ -336,11 +336,6 @@ export namespace R {
|
||||||
room_id: string
|
room_id: string
|
||||||
room_type?: string
|
room_type?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ResolvedRoom = {
|
|
||||||
room_id: string
|
|
||||||
servers: string[]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Pagination<T> = {
|
export type Pagination<T> = {
|
||||||
|
|
|
@ -11,7 +11,7 @@ mixin badge-private
|
||||||
| Private
|
| Private
|
||||||
|
|
||||||
mixin discord(channel, radio=false)
|
mixin discord(channel, radio=false)
|
||||||
- let permissions = dUtils.getPermissions([], guild.roles, null, channel.permission_overwrites)
|
- let permissions = dUtils.getPermissions([], discord.guilds.get(channel.guild_id).roles, null, channel.permission_overwrites)
|
||||||
.s-user-card.s-user-card__small
|
.s-user-card.s-user-card__small
|
||||||
if !dUtils.hasPermission(permissions, DiscordTypes.PermissionFlagsBits.ViewChannel)
|
if !dUtils.hasPermission(permissions, DiscordTypes.PermissionFlagsBits.ViewChannel)
|
||||||
!= icons.Icons.IconLock
|
!= icons.Icons.IconLock
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue