Fix matrix api joinRoom() for remote rooms #60
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "Elliu/out-of-your-element:fix-remote-join"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.
It seems like the "via" information can also be stored in the
"m.space.parent" in the states of the room, but hopefully this shouldn't
be needed in sane implementations
@ -149,2 +160,3 @@
await api.joinRoom(parsedBody.matrix, null, via ?? {})
} catch (e) {
throw createError({status: 403, message: e.errcode, data: `${e.errcode} - ${e.message}`})
throw createError({status: 403, message: e.errcode, data: `${e.errcode} - ${e.message}${via === null ? " (hint: couln't find a \"via\" in the space children_state for this room in order to help joining this room)" : ""}`})
Not sure if adding this hint is a good idea, or if we should rather put it elsewhere (like in a "hint" member), or if we should not put it at all, or if we should add a "please consider manually inviting the bot user <> in the room"
I added a separate branch for it to say a different error message when the join fails. I felt the ternary was too complicated.
I decided to do it this way because it's better to see actionable feedback (do this) rather than merely identifying a problem (it tells you that the via data is wrong, but not what correct data would look like, or how to actually fix it) (I don't know any clients that allow you to edit the via data without devtools)
e8bb63dd3a
to743fec6e69
@ -23,3 +23,3 @@
if (mxid) u.searchParams.set("user_id", mxid)
for (const entry of Object.entries(otherParams)) {
if (entry[1] != undefined) {
if (Array.isArray(entry[1])) {
I fixed
path
so that passing arrays (likevia
) to it should work correctly. :)@ -68,2 +74,3 @@
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}), {})
Third parameter needs to be an object, so I fixed that for you. I also labelled the inbound parameters so that it highlights the call site if the wrong data is passed to
joinRoom
. :)@ -78,3 +78,3 @@
// Check space exists and bridge is joined
try {
await api.joinRoom(parsedBody.space_id)
await api.joinRoom(parsedBody.space_id, null, via)
Where are you going to find
via
here?Hmmm, I didn't change that because the bridge needed to be manually invited to the space so that it can be selected.
However indeed, if the bridge is invited to the space, then kicked, the button to the space remains and if clicked, we have the same issue than for joining rooms, didn't notice that.
From the Client-Server API doc there doesn't seem to be "via" or "server_name" information on the
m.room.member
event, so I'm not sure.I guess it should be safe to take the HS part of the user from
sender
in them.room.member
: as this user is able to send an invite, the space must be reachable through the inviter's HS(unless the invite is old, all users from this HS left the space, and the room was purged from the HS, but nothing we can do about that)
Last commit uses that, should we add a check to enrich the error message too if for some reasons we cannot detect the via?
Added the error message asking to manually invite in case if /api/link-space joinRoom fails, similarly to /api/link
b6c3e37478
to6734c15ca2
48e2080b94
tof6c749acca
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.