From b8793dae0f7e33bf7cb74d98d843c1369825a662 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Mon, 26 Aug 2024 01:42:56 +1200 Subject: [PATCH] Sync new power system to newly created rooms --- d2m/actions/create-room.js | 4 +++- d2m/actions/create-space.js | 7 +++++-- test/ooye-test-data.sql | 3 +++ test/test.js | 1 - 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/d2m/actions/create-room.js b/d2m/actions/create-room.js index 051e889e..322f8be9 100644 --- a/d2m/actions/create-room.js +++ b/d2m/actions/create-room.js @@ -142,6 +142,8 @@ async function channelToKState(channel, guild) { const everyonePermissions = utils.getPermissions([], guild.roles, undefined, channel.permission_overwrites) const everyoneCanMentionEveryone = utils.hasAllPermissions(everyonePermissions, ["MentionEveryone"]) + const globalAdmins = select("member_power", ["mxid", "power_level"], {room_id: "*"}).all() + const channelKState = { "m.room.name/": {name: convertedName}, "m.room.topic/": {topic: convertedTopic}, @@ -161,7 +163,7 @@ async function channelToKState(channel, guild) { notifications: { room: everyoneCanMentionEveryone ? 0 : 20 }, - users: reg.ooye.invite.reduce((a, c) => (a[c] = 100, a), {}) + users: globalAdmins.reduce((a, c) => (a[c.mxid] = c.power_level, a), {}) }, "chat.schildi.hide_ui/read_receipts": { hidden: true diff --git a/d2m/actions/create-space.js b/d2m/actions/create-space.js index dbefd6d0..44d0206e 100644 --- a/d2m/actions/create-space.js +++ b/d2m/actions/create-space.js @@ -31,6 +31,8 @@ async function createSpace(guild, kstate) { const topic = kstate["m.room.topic/"]?.topic || undefined assert(name) + const globalAdmins = select("member_power", "mxid", {room_id: "*"}).pluck().all() + const roomID = await createRoom.postApplyPowerLevels(kstate, async kstate => { return api.createRoom({ name, @@ -40,7 +42,7 @@ async function createSpace(guild, kstate) { events_default: 100, // space can only be managed by bridge invite: 0 // any existing member can invite others }, - invite: reg.ooye.invite, + invite: globalAdmins, topic, creation_content: { type: "m.space" @@ -58,6 +60,7 @@ async function createSpace(guild, kstate) { */ async function guildToKState(guild, privacyLevel) { assert.equal(typeof privacyLevel, "number") + const globalAdmins = select("member_power", ["mxid", "power_level"], {room_id: "*"}).all() const guildKState = { "m.room.name/": {name: guild.name}, "m.room.avatar/": { @@ -68,7 +71,7 @@ async function guildToKState(guild, privacyLevel) { "m.room.guest_access/": {guest_access: createRoom.PRIVACY_ENUMS.GUEST_ACCESS[privacyLevel]}, "m.room.history_visibility/": {history_visibility: createRoom.PRIVACY_ENUMS.SPACE_HISTORY_VISIBILITY[privacyLevel]}, "m.room.join_rules/": {join_rule: createRoom.PRIVACY_ENUMS.SPACE_JOIN_RULES[privacyLevel]}, - "m.room.power_levels/": {users: reg.ooye.invite.reduce((a, c) => (a[c] = 100, a), {})} + "m.room.power_levels/": {users: globalAdmins.reduce((a, c) => (a[c.mxid] = c.power_level, a), {})} // used in guild initial creation postApplyPowerLevels } return guildKState diff --git a/test/ooye-test-data.sql b/test/ooye-test-data.sql index 328c4b33..1fb9e244 100644 --- a/test/ooye-test-data.sql +++ b/test/ooye-test-data.sql @@ -139,6 +139,9 @@ INSERT INTO member_cache (room_id, mxid, displayname, avatar_url) VALUES ('!TqlyQmifxGUggEmdBN:cadence.moe', '@cadence:cadence.moe', 'cadence [they]', NULL), ('!BnKuBPCvyfOkhcUjEu:cadence.moe', '@ami:the-apothecary.club', 'Ami (she/her)', NULL); +INSERT INTO member_power (mxid, room_id, power_level) VALUES +('@test_auto_invite:example.org', '*', 100); + INSERT INTO lottie (sticker_id, mxc_url) VALUES ('860171525772279849', 'mxc://cadence.moe/ZtvvVbwMIdUZeovWVyGVFCeR'); diff --git a/test/test.js b/test/test.js index 396dea96..b5977f18 100644 --- a/test/test.js +++ b/test/test.js @@ -20,7 +20,6 @@ const db = new sqlite(":memory:") const reg = require("../matrix/read-registration") reg.ooye.server_origin = "https://matrix.cadence.moe" // so that tests will pass even when hard-coded reg.ooye.server_name = "cadence.moe" -reg.ooye.invite = ["@test_auto_invite:example.org"] reg.id = "baby" // don't actually take authenticated actions on the server reg.as_token = "baby" reg.hs_token = "baby"