mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-27 07:28:27 +00:00
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.
This commit is contained in:
parent
d4918b83c6
commit
7edf197ecc
2 changed files with 53 additions and 20 deletions
|
@ -58,27 +58,12 @@ func SendMembership(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inviteStored, err := threepid.CheckAndProcessInvite(
|
inviteStored, jsonErrResp := checkAndProcessThreepid(
|
||||||
req.Context(), device, &body, cfg, queryAPI, accountDB, producer,
|
req, device, &body, cfg, queryAPI, accountDB, producer,
|
||||||
membership, roomID, evTime,
|
membership, roomID, evTime,
|
||||||
)
|
)
|
||||||
if err == threepid.ErrMissingParameter {
|
if jsonErrResp != nil {
|
||||||
return util.JSONResponse{
|
return *jsonErrResp
|
||||||
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 an invite has been stored on an identity server, it means that a
|
// 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)
|
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{
|
return util.JSONResponse{
|
||||||
Code: http.StatusOK,
|
Code: http.StatusOK,
|
||||||
JSON: struct{}{},
|
JSON: returnData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,3 +209,41 @@ func getMembershipStateKey(
|
||||||
|
|
||||||
return
|
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
|
||||||
|
}
|
||||||
|
|
1
testfile
1
testfile
|
@ -42,6 +42,7 @@ POST /join/:room_alias can join a room
|
||||||
POST /join/:room_id can join a room
|
POST /join/:room_id can join a room
|
||||||
POST /join/:room_id can join a room with custom content
|
POST /join/:room_id can join a room with custom content
|
||||||
POST /join/:room_alias can join a room with custom content
|
POST /join/:room_alias can join a room with custom content
|
||||||
|
POST /rooms/:room_id/join can join a room
|
||||||
POST /rooms/:room_id/leave can leave a room
|
POST /rooms/:room_id/leave can leave a room
|
||||||
POST /rooms/:room_id/invite can send an invite
|
POST /rooms/:room_id/invite can send an invite
|
||||||
POST /rooms/:room_id/ban can ban a user
|
POST /rooms/:room_id/ban can ban a user
|
||||||
|
|
Loading…
Reference in a new issue