mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-15 10:53:09 -06:00
checkAndProcessThreepid function added in membership.go to reduce reduce the complexity of SendMembership in order to Fix response to /rooms/{roomId}/join
This commit is contained in:
parent
9329b571bb
commit
a85652dc38
|
|
@ -58,27 +58,12 @@ func SendMembership(
|
|||
}
|
||||
}
|
||||
|
||||
inviteStored, err := threepid.CheckAndProcessInvite(
|
||||
req.Context(), device, &body, cfg, queryAPI, accountDB, producer,
|
||||
inviteStored, errRes := 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 errRes != nil {
|
||||
return *errRes
|
||||
}
|
||||
|
||||
// If an invite has been stored on an identity server, it means that a
|
||||
|
|
@ -114,6 +99,15 @@ func SendMembership(
|
|||
return httputil.LogThenError(req, err)
|
||||
}
|
||||
|
||||
if membership == "join" {
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusOK,
|
||||
JSON: struct {
|
||||
RoomID string `json:"room_id"`
|
||||
}{roomID},
|
||||
}
|
||||
}
|
||||
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusOK,
|
||||
JSON: struct{}{},
|
||||
|
|
@ -215,3 +209,35 @@ 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 string, 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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,14 +95,7 @@ func Setup(
|
|||
r0mux.Handle("/rooms/{roomID}/{membership:(?:join|kick|ban|unban|leave|invite)}",
|
||||
common.MakeAuthAPI("membership", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
||||
vars := mux.Vars(req)
|
||||
r := SendMembership(req, accountDB, device, vars["roomID"], vars["membership"], cfg, queryAPI, asAPI, producer)
|
||||
if r.Code == http.StatusOK && vars["membership"] == "join" {
|
||||
r.JSON = struct {
|
||||
RoomID string `json:"room_id"`
|
||||
}{vars["roomID"]}
|
||||
return r
|
||||
}
|
||||
return r
|
||||
return SendMembership(req, accountDB, device, vars["roomID"], vars["membership"], cfg, queryAPI, asAPI, producer)
|
||||
}),
|
||||
).Methods(http.MethodPost, http.MethodOptions)
|
||||
r0mux.Handle("/rooms/{roomID}/send/{eventType}",
|
||||
|
|
|
|||
Loading…
Reference in a new issue