From b6c3e37478b3c11d54d546cdb6abe78095f85b0b Mon Sep 17 00:00:00 2001 From: Elliu Date: Sat, 23 Aug 2025 00:01:30 +0900 Subject: [PATCH] Fix /api/link-space joinRoom() for remote spaces --- src/web/routes/link.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/web/routes/link.js b/src/web/routes/link.js index f85e66d..ef96ea9 100644 --- a/src/web/routes/link.js +++ b/src/web/routes/link.js @@ -12,6 +12,16 @@ const auth = sync.require("../auth") const mreq = sync.require("../../matrix/mreq") const {reg} = require("../../matrix/read-registration") +/** + * @param {string} UserID + * @returns {string} the HS of the user, or "" if the user ID is malformed + */ +function getHSOfUser(user) { + /* c8 ignore next */ + return user.partition(":")[2] +} + + /** * @param {H3Event} event * @returns {import("../../matrix/api")} @@ -75,6 +85,9 @@ as.router.post("/api/link-space", defineEventHandler(async event => { const existing = select("guild_space", "guild_id", {}, "WHERE guild_id = ? OR space_id = ?").get(guildID, spaceID) if (existing) throw createError({status: 400, message: "Bad Request", data: `Guild ID ${guildID} or space ID ${spaceID} are already bridged and cannot be reused`}) + const inviteSender = select("invite", "mxid", {mxid: session.data.mxid, room_id: spaceID}).pluck().get() + via = [ getHSOfUser(inviteSender) ] + // Check space exists and bridge is joined try { await api.joinRoom(parsedBody.space_id, null, via)