This commit is contained in:
Neil Alexander 2021-07-26 10:03:49 +01:00
parent ae4416066a
commit 9ddd47fbf0
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -38,34 +38,31 @@ func InviteV2(
rsAPI api.RoomserverInternalAPI, rsAPI api.RoomserverInternalAPI,
keys gomatrixserverlib.JSONVerifier, keys gomatrixserverlib.JSONVerifier,
) util.JSONResponse { ) util.JSONResponse {
inviteReq := gomatrixserverlib.InviteV2Request{} inviteReq := gomatrixserverlib.InviteV2Request{}
err := json.Unmarshal(request.Content(), &inviteReq) err := json.Unmarshal(request.Content(), &inviteReq)
// Check to see if the room_version is supported switch e := err.(type) {
if _, err := roomserverVersion.SupportedRoomVersion(inviteReq.RoomVersion()); err != nil { case gomatrixserverlib.UnsupportedRoomVersionError:
return util.JSONResponse{ return util.JSONResponse{
Code: http.StatusBadRequest, Code: http.StatusBadRequest,
JSON: jsonerror.UnsupportedRoomVersion( JSON: jsonerror.UnsupportedRoomVersion(
fmt.Sprintf("Room version %q is not supported by this server.", inviteReq.RoomVersion()), fmt.Sprintf("Room version %q is not supported by this server.", e.Version),
), ),
} }
}
switch err.(type) {
case gomatrixserverlib.BadJSONError: case gomatrixserverlib.BadJSONError:
return util.JSONResponse{ return util.JSONResponse{
Code: http.StatusBadRequest, Code: http.StatusBadRequest,
JSON: jsonerror.BadJSON(err.Error()), JSON: jsonerror.BadJSON(err.Error()),
} }
case nil: case nil:
return processInvite(
httpReq.Context(), true, inviteReq.Event(), inviteReq.RoomVersion(), inviteReq.InviteRoomState(), roomID, eventID, cfg, rsAPI, keys,
)
default: default:
return util.JSONResponse{ return util.JSONResponse{
Code: http.StatusBadRequest, Code: http.StatusBadRequest,
JSON: jsonerror.NotJSON("The request body could not be decoded into an invite request. " + err.Error()), JSON: jsonerror.NotJSON("The request body could not be decoded into an invite request. " + err.Error()),
} }
} }
return processInvite(
httpReq.Context(), true, inviteReq.Event(), inviteReq.RoomVersion(), inviteReq.InviteRoomState(), roomID, eventID, cfg, rsAPI, keys,
)
} }
// InviteV1 implements /_matrix/federation/v1/invite/{roomID}/{eventID} // InviteV1 implements /_matrix/federation/v1/invite/{roomID}/{eventID}