MakeJoin implements the /make_join API
( httpReq *http.Request, request *gomatrixserverlib.FederationRequest, cfg *config.FederationAPI, rsAPI api.FederationRoomserverAPI, roomID, userID string, remoteVersions []gomatrixserverlib.RoomVersion, )
| 33 | |
| 34 | // MakeJoin implements the /make_join API |
| 35 | func MakeJoin( |
| 36 | httpReq *http.Request, |
| 37 | request *gomatrixserverlib.FederationRequest, |
| 38 | cfg *config.FederationAPI, |
| 39 | rsAPI api.FederationRoomserverAPI, |
| 40 | roomID, userID string, |
| 41 | remoteVersions []gomatrixserverlib.RoomVersion, |
| 42 | ) util.JSONResponse { |
| 43 | verReq := api.QueryRoomVersionForRoomRequest{RoomID: roomID} |
| 44 | verRes := api.QueryRoomVersionForRoomResponse{} |
| 45 | if err := rsAPI.QueryRoomVersionForRoom(httpReq.Context(), &verReq, &verRes); err != nil { |
| 46 | return util.JSONResponse{ |
| 47 | Code: http.StatusInternalServerError, |
| 48 | JSON: jsonerror.InternalServerError(), |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | // Check that the room that the remote side is trying to join is actually |
| 53 | // one of the room versions that they listed in their supported ?ver= in |
| 54 | // the make_join URL. |
| 55 | // https://matrix.org/docs/spec/server_server/r0.1.3#get-matrix-federation-v1-make-join-roomid-userid |
| 56 | remoteSupportsVersion := false |
| 57 | for _, v := range remoteVersions { |
| 58 | if v == verRes.RoomVersion { |
| 59 | remoteSupportsVersion = true |
| 60 | break |
| 61 | } |
| 62 | } |
| 63 | // If it isn't, stop trying to join the room. |
| 64 | if !remoteSupportsVersion { |
| 65 | return util.JSONResponse{ |
| 66 | Code: http.StatusBadRequest, |
| 67 | JSON: jsonerror.IncompatibleRoomVersion(verRes.RoomVersion), |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | _, domain, err := gomatrixserverlib.SplitID('@', userID) |
| 72 | if err != nil { |
| 73 | return util.JSONResponse{ |
| 74 | Code: http.StatusBadRequest, |
| 75 | JSON: jsonerror.BadJSON("Invalid UserID"), |
| 76 | } |
| 77 | } |
| 78 | if domain != request.Origin() { |
| 79 | return util.JSONResponse{ |
| 80 | Code: http.StatusForbidden, |
| 81 | JSON: jsonerror.Forbidden("The join must be sent by the server of the user"), |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | // Check if we think we are still joined to the room |
| 86 | inRoomReq := &api.QueryServerJoinedToRoomRequest{ |
| 87 | ServerName: cfg.Matrix.ServerName, |
| 88 | RoomID: roomID, |
| 89 | } |
| 90 | inRoomRes := &api.QueryServerJoinedToRoomResponse{} |
| 91 | if err = rsAPI.QueryServerJoinedToRoom(httpReq.Context(), inRoomReq, inRoomRes); err != nil { |
| 92 | util.GetLogger(httpReq.Context()).WithError(err).Error("rsAPI.QueryServerJoinedToRoom failed") |
no test coverage detected