Some tweaks
This commit is contained in:
parent
54a79892e1
commit
af860fc6fa
|
@ -184,34 +184,8 @@ func SendLeave(
|
|||
}
|
||||
}
|
||||
|
||||
verImpl, err := gomatrixserverlib.GetRoomVersion(roomVersion)
|
||||
if err != nil {
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusInternalServerError,
|
||||
JSON: spec.UnsupportedRoomVersion(
|
||||
fmt.Sprintf("QueryRoomVersionForRoom returned unknown version: %s", roomVersion),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// Decode the event JSON from the request.
|
||||
event, err := verImpl.NewEventFromUntrustedJSON(request.Content())
|
||||
switch err.(type) {
|
||||
case gomatrixserverlib.BadJSONError:
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusBadRequest,
|
||||
JSON: spec.BadJSON(err.Error()),
|
||||
}
|
||||
case nil:
|
||||
default:
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusBadRequest,
|
||||
JSON: spec.NotJSON("The request body could not be decoded into valid JSON. " + err.Error()),
|
||||
}
|
||||
}
|
||||
|
||||
leaveEvent, err := gomatrixserverlib.HandleSendLeave(
|
||||
httpReq.Context(), incomingEvent, request.Origin(), roomVersion, eventID, roomID, rsAPI, keys)
|
||||
httpReq.Context(), request.Content(), request.Origin(), roomVersion, eventID, roomID, rsAPI, keys)
|
||||
|
||||
switch e := err.(type) {
|
||||
case nil:
|
||||
|
@ -247,6 +221,15 @@ func SendLeave(
|
|||
}
|
||||
}
|
||||
|
||||
// The user was never joined to the room, has already left,
|
||||
// or we already processed this leave event, so this is a no-op.
|
||||
if leaveEvent == nil {
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusOK,
|
||||
JSON: struct{}{},
|
||||
}
|
||||
}
|
||||
|
||||
// Send the events to the room server.
|
||||
// We are responsible for notifying other servers that the user has left
|
||||
// the room, so set SendAsServer to cfg.Matrix.ServerName
|
||||
|
|
Loading…
Reference in a new issue