From efa98b35eee1584546d2b8c5fdedc2c09e50c626 Mon Sep 17 00:00:00 2001 From: Cnly Date: Thu, 10 Jan 2019 11:08:42 +0800 Subject: [PATCH] POST /join/{roomId}: Allow joining even when not invited #663 Signed-off-by: Alex Chen --- .../dendrite/clientapi/routing/joinroom.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/github.com/matrix-org/dendrite/clientapi/routing/joinroom.go b/src/github.com/matrix-org/dendrite/clientapi/routing/joinroom.go index 98c7cd6a7..760e46d0b 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/routing/joinroom.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/joinroom.go @@ -119,16 +119,14 @@ func (r joinRoomReq) joinRoomByID(roomID string) util.JSONResponse { return httputil.LogThenError(r.req, err) } if len(queryRes.InviteSenderUserIDs) == 0 { - // TODO: We might need to support clients which erroneously try to join - // the room by ID even when they are not invited. - // This can be done by removing this check and falling through to - // joinRoomUsingServers passing an empty list since joinRoomUserServers - // will check if we are already in the room first. - return util.JSONResponse{ - Code: http.StatusForbidden, - JSON: jsonerror.Forbidden("You are not invited to the room"), + // Support clients erroneously trying to join without an invite + _, domain, err := gomatrixserverlib.SplitID('!', roomID) + if err != nil { + return httputil.LogThenError(r.req, err) } + return r.joinRoomUsingServers(roomID, []gomatrixserverlib.ServerName{domain}) } + servers := []gomatrixserverlib.ServerName{} seenBefore := map[gomatrixserverlib.ServerName]bool{} for _, userID := range queryRes.InviteSenderUserIDs {