Fix matrix api joinRoom() for remote rooms #60
1 changed files with 17 additions and 0 deletions
|
|
@ -12,6 +12,20 @@ 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) {
|
||||
|
|
||||
domainStartIndex = user.indexOf(":");
|
||||
if (domainStartIndex >= 1) {
|
||||
return user.slice(domainStartIndex + 1)
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {H3Event} event
|
||||
* @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)
|
||||
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) ]
|
||||
|
cadence
commented
When creating a new variable, it ought to be declared with 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
|
||||
try {
|
||||
await api.joinRoom(parsedBody.space_id, null, via)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue
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 functiongetHSOfUserand 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