diff options
author | Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> | 2019-07-12 14:29:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-12 14:29:30 +0100 |
commit | 7edf197eccc89cb7368ed31df47c9d15f24d0923 (patch) | |
tree | d27e49e5d431d8db6c8e31d8a38f2c605b9a96a8 /clientapi/routing | |
parent | d4918b83c6f0fe0c6578d53a1c22d02a37c0d8b9 (diff) |
Fix response to /rooms/{roomId}/join v2 (#734)
Continuation of #684 but merged-forward.
Also did a little code cleanup and added a new, passing test to the testfile.
Diffstat (limited to 'clientapi/routing')
-rw-r--r-- | clientapi/routing/membership.go | 72 |
1 files changed, 52 insertions, 20 deletions
diff --git a/clientapi/routing/membership.go b/clientapi/routing/membership.go index b308de79..22e66f45 100644 --- a/clientapi/routing/membership.go +++ b/clientapi/routing/membership.go @@ -58,27 +58,12 @@ func SendMembership( } } - inviteStored, err := threepid.CheckAndProcessInvite( - req.Context(), device, &body, cfg, queryAPI, accountDB, producer, + inviteStored, jsonErrResp := checkAndProcessThreepid( + req, device, &body, cfg, queryAPI, accountDB, producer, membership, roomID, evTime, ) - if err == threepid.ErrMissingParameter { - return util.JSONResponse{ - Code: http.StatusBadRequest, - JSON: jsonerror.BadJSON(err.Error()), - } - } else if err == threepid.ErrNotTrusted { - return util.JSONResponse{ - Code: http.StatusBadRequest, - JSON: jsonerror.NotTrusted(body.IDServer), - } - } else if err == common.ErrRoomNoExists { - return util.JSONResponse{ - Code: http.StatusNotFound, - JSON: jsonerror.NotFound(err.Error()), - } - } else if err != nil { - return httputil.LogThenError(req, err) + if jsonErrResp != nil { + return *jsonErrResp } // If an invite has been stored on an identity server, it means that a @@ -114,9 +99,18 @@ func SendMembership( return httputil.LogThenError(req, err) } + var returnData interface{} = struct{}{} + + // The join membership requires the room id to be sent in the response + if membership == "join" { + returnData = struct { + RoomID string `json:"room_id"` + }{roomID} + } + return util.JSONResponse{ Code: http.StatusOK, - JSON: struct{}{}, + JSON: returnData, } } @@ -215,3 +209,41 @@ func getMembershipStateKey( return } + +func checkAndProcessThreepid( + req *http.Request, + device *authtypes.Device, + body *threepid.MembershipRequest, + cfg config.Dendrite, + queryAPI roomserverAPI.RoomserverQueryAPI, + accountDB *accounts.Database, + producer *producers.RoomserverProducer, + membership, roomID string, + evTime time.Time, +) (inviteStored bool, errRes *util.JSONResponse) { + + inviteStored, err := threepid.CheckAndProcessInvite( + req.Context(), device, body, cfg, queryAPI, accountDB, producer, + membership, roomID, evTime, + ) + if err == threepid.ErrMissingParameter { + return inviteStored, &util.JSONResponse{ + Code: http.StatusBadRequest, + JSON: jsonerror.BadJSON(err.Error()), + } + } else if err == threepid.ErrNotTrusted { + return inviteStored, &util.JSONResponse{ + Code: http.StatusBadRequest, + JSON: jsonerror.NotTrusted(body.IDServer), + } + } else if err == common.ErrRoomNoExists { + return inviteStored, &util.JSONResponse{ + Code: http.StatusNotFound, + JSON: jsonerror.NotFound(err.Error()), + } + } else if err != nil { + er := httputil.LogThenError(req, err) + return inviteStored, &er + } + return +} |