Fix matrix api joinRoom() for remote rooms (#60)
When using self-service mode and trying to link with a remote matrix room (room not in the same HS as the bridge user), then we need to add the "via" HSs to join the room with, or else it fails. We get it from the "m.space.child" in the "children_state" of the space hierarchy. Co-authored-by: Cadence Ember <cadence@disroot.org> Reviewed-on: https://gitdab.com/cadence/out-of-your-element/pulls/60 Co-authored-by: Elliu <elliu@hashi.re> Co-committed-by: Elliu <elliu@hashi.re>
This commit is contained in:
committed by
cadence
co-authored by
Cadence Ember
parent
255e166e8c
commit
d95a114377
+10
-3
@@ -22,7 +22,11 @@ function path(p, mxid, otherParams = {}) {
|
||||
const u = new URL(p, "http://localhost")
|
||||
if (mxid) u.searchParams.set("user_id", mxid)
|
||||
for (const entry of Object.entries(otherParams)) {
|
||||
if (entry[1] != undefined) {
|
||||
if (Array.isArray(entry[1])) {
|
||||
for (const element of entry[1]) {
|
||||
u.searchParams.append(entry[0], element)
|
||||
}
|
||||
} else if (entry[1] != undefined) {
|
||||
u.searchParams.set(entry[0], entry[1])
|
||||
}
|
||||
}
|
||||
@@ -62,11 +66,14 @@ async function createRoom(content) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} roomIDOrAlias
|
||||
* @param {string?} [mxid]
|
||||
* @param {string[]?} [via]
|
||||
* @returns {Promise<string>} room ID
|
||||
*/
|
||||
async function joinRoom(roomIDOrAlias, mxid) {
|
||||
async function joinRoom(roomIDOrAlias, mxid, via) {
|
||||
/** @type {Ty.R.RoomJoined} */
|
||||
const root = await mreq.mreq("POST", path(`/client/v3/join/${roomIDOrAlias}`, mxid), {})
|
||||
const root = await mreq.mreq("POST", path(`/client/v3/join/${roomIDOrAlias}`, mxid, {via}), {})
|
||||
return root.room_id
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user