Some tweaks

This commit is contained in:
Till Faelligen 2023-11-23 12:21:01 +01:00
parent 54a79892e1
commit af860fc6fa
No known key found for this signature in database
GPG key ID: ACCDC9606D472758

View file

@ -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( 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) { switch e := err.(type) {
case nil: 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. // Send the events to the room server.
// We are responsible for notifying other servers that the user has left // We are responsible for notifying other servers that the user has left
// the room, so set SendAsServer to cfg.Matrix.ServerName // the room, so set SendAsServer to cfg.Matrix.ServerName