mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-27 07:28:27 +00:00
* Fix #2084 * Return early * Linting
This commit is contained in:
parent
161f145176
commit
173b1e8d3e
3 changed files with 52 additions and 5 deletions
|
@ -16,6 +16,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
|
@ -29,15 +30,42 @@ func GetEventAuth(
|
||||||
roomID string,
|
roomID string,
|
||||||
eventID string,
|
eventID string,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
// TODO: Optimisation: we shouldn't be querying all the room state
|
event, resErr := fetchEvent(ctx, rsAPI, eventID)
|
||||||
// that is in state.StateEvents - we just ignore it.
|
if resErr != nil {
|
||||||
state, err := getState(ctx, request, rsAPI, roomID, eventID)
|
return *resErr
|
||||||
|
}
|
||||||
|
|
||||||
|
if event.RoomID() != roomID {
|
||||||
|
return util.JSONResponse{Code: http.StatusNotFound, JSON: jsonerror.NotFound("event does not belong to this room")}
|
||||||
|
}
|
||||||
|
resErr = allowedToSeeEvent(ctx, request.Origin(), rsAPI, eventID)
|
||||||
|
if resErr != nil {
|
||||||
|
return *resErr
|
||||||
|
}
|
||||||
|
|
||||||
|
var response api.QueryStateAndAuthChainResponse
|
||||||
|
err := rsAPI.QueryStateAndAuthChain(
|
||||||
|
ctx,
|
||||||
|
&api.QueryStateAndAuthChainRequest{
|
||||||
|
RoomID: roomID,
|
||||||
|
PrevEventIDs: []string{eventID},
|
||||||
|
AuthEventIDs: event.AuthEventIDs(),
|
||||||
|
OnlyFetchAuthChain: true,
|
||||||
|
},
|
||||||
|
&response,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return *err
|
return util.ErrorResponse(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !response.RoomExists {
|
||||||
|
return util.JSONResponse{Code: http.StatusNotFound, JSON: nil}
|
||||||
}
|
}
|
||||||
|
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusOK,
|
Code: http.StatusOK,
|
||||||
JSON: gomatrixserverlib.RespEventAuth{AuthEvents: state.AuthEvents},
|
JSON: gomatrixserverlib.RespEventAuth{
|
||||||
|
AuthEvents: gomatrixserverlib.UnwrapEventHeaders(response.AuthChainEvents),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,6 +226,10 @@ type QueryStateAndAuthChainRequest struct {
|
||||||
PrevEventIDs []string `json:"prev_event_ids"`
|
PrevEventIDs []string `json:"prev_event_ids"`
|
||||||
// The list of auth events for the event. Used to calculate the auth chain
|
// The list of auth events for the event. Used to calculate the auth chain
|
||||||
AuthEventIDs []string `json:"auth_event_ids"`
|
AuthEventIDs []string `json:"auth_event_ids"`
|
||||||
|
// If true, the auth chain events for the auth event IDs given will be fetched only. Prev event IDs are ignored.
|
||||||
|
// If false, state and auth chain events for the prev event IDs and entire current state will be included.
|
||||||
|
// TODO: not a great API shape. It serves 2 main uses: false=>response for send_join, true=>response for /event_auth
|
||||||
|
OnlyFetchAuthChain bool `json:"only_fetch_auth_chain"`
|
||||||
// Should state resolution be ran on the result events?
|
// Should state resolution be ran on the result events?
|
||||||
// TODO: check call sites and remove if we always want to do state res
|
// TODO: check call sites and remove if we always want to do state res
|
||||||
ResolveState bool `json:"resolve_state"`
|
ResolveState bool `json:"resolve_state"`
|
||||||
|
|
|
@ -457,6 +457,21 @@ func (r *Queryer) QueryStateAndAuthChain(
|
||||||
response.RoomExists = true
|
response.RoomExists = true
|
||||||
response.RoomVersion = info.RoomVersion
|
response.RoomVersion = info.RoomVersion
|
||||||
|
|
||||||
|
// handle this entirely separately to the other case so we don't have to pull out
|
||||||
|
// the entire current state of the room
|
||||||
|
// TODO: this probably means it should be a different query operation...
|
||||||
|
if request.OnlyFetchAuthChain {
|
||||||
|
var authEvents []*gomatrixserverlib.Event
|
||||||
|
authEvents, err = GetAuthChain(ctx, r.DB.EventsFromIDs, request.AuthEventIDs)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, event := range authEvents {
|
||||||
|
response.AuthChainEvents = append(response.AuthChainEvents, event.Headered(info.RoomVersion))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var stateEvents []*gomatrixserverlib.Event
|
var stateEvents []*gomatrixserverlib.Event
|
||||||
stateEvents, err = r.loadStateAtEventIDs(ctx, *info, request.PrevEventIDs)
|
stateEvents, err = r.loadStateAtEventIDs(ctx, *info, request.PrevEventIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue