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 7932f8af85 - Show all commits

View file

@ -96,6 +96,9 @@ as.router.post("/api/link-space", defineEventHandler(async event => {
try {
await api.joinRoom(parsedBody.space_id, null, via)
} catch (e) {
if (via.join("") == "") {

This condition can't happen, because it's always possible to extract a via from the user who sent the invite. Remove the if statement and just always use the more detailed error message.

This condition can't happen, because it's always possible to extract a `via` from the user who sent the invite. Remove the if statement and just always use the more detailed error message.
throw createError({status: 403, message: "Unable To Join", data: `Unable to join the requested Matrix space. Please invite the bridge to the space and try again. (Server said: ${e.errcode} - ${e.message})`})

Status code 400 please.

Note that this error message doesn't make much sense. The user has to have already invited the bridge to the space to reach this point.

I honestly don't know what advice would be good to give if this occurs, because accepting an invite should always work, even for remote invites. /shrug

Status code 400 please. Note that this error message doesn't make much sense. The user has to have already invited the bridge to the space to reach this point. I honestly don't know what advice would be good to give if this occurs, because accepting an invite should always work, even for remote invites. /shrug

Yeah, I don't know.
The idea at the back of my mind was a weird state that could happen if:

  1. Space is not on the same HS than bridge
  2. Bridge is invited / join the space
  3. User kicks / remove the bridge from the space
  4. User leave the space
  5. No remaining user from this HS on the space, space is purged from the user's HS
  6. /api/link-space gets called somehow(?)
  7. bridge tries to join using the "via" of origin invite, but space got purged from the via-ed HS in between, so fails, requiring a reinvite from a user that is currently in the space

Don't know if all of this even makes sense

Yeah, I don't know. The idea at the back of my mind was a weird state that could happen if: 1. Space is not on the same HS than bridge 1. Bridge is invited / join the space 2. User kicks / remove the bridge from the space 3. User leave the space 4. No remaining user from this HS on the space, space is purged from the user's HS 5. `/api/link-space` gets called somehow(?) 6. bridge tries to join using the "via" of origin invite, but space got purged from the via-ed HS in between, so fails, requiring a reinvite from a user that is currently in the space Don't know if all of this even makes sense
}
throw createError({status: 403, message: e.errcode, data: `${e.errcode} - ${e.message}`})
}