Fix matrix api joinRoom() for remote rooms #60

Merged
cadence merged 9 commits from Elliu/out-of-your-element:fix-remote-join into main 2025-11-02 07:50:16 +00:00
Showing only changes of commit e7b4dfea9c - Show all commits

View file

@ -12,6 +12,20 @@ const auth = sync.require("../auth")
const mreq = sync.require("../../matrix/mreq") const mreq = sync.require("../../matrix/mreq")
const {reg} = require("../../matrix/read-registration") 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) {

Please use server = mxid.match(/:(.*)/)?.[1] (see utils.js line 168) which is short enough that it can be used inline without needing to be extracted to a function. So please delete the function getHSOfUser and just do the operation inline where needed.

Please use `server = mxid.match(/:(.*)/)?.[1]` (see utils.js line 168) which is short enough that it can be used inline without needing to be extracted to a function. So please delete the function `getHSOfUser` and just do the operation inline where needed.

Updated, had to add a null coalescing or else linter complains about array of string OR undefined a few lines below

Updated, had to add a null coalescing or else linter complains about array of string OR undefined a few lines below
domainStartIndex = user.indexOf(":");
if (domainStartIndex >= 1) {
return user.slice(domainStartIndex + 1)
}
return ""
}
/** /**
* @param {H3Event} event * @param {H3Event} event
* @returns {import("../../matrix/api")} * @returns {import("../../matrix/api")}
@ -75,6 +89,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) 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`}) 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) ]

When creating a new variable, it ought to be declared with let or const. Please use const here.

When creating a new variable, it ought to be declared with `let` or `const`. Please use `const` here.
// Check space exists and bridge is joined // Check space exists and bridge is joined
try { try {
await api.joinRoom(parsedBody.space_id, null, via) await api.joinRoom(parsedBody.space_id, null, via)