Wire in new code

This commit is contained in:
Neil Alexander 2021-07-15 15:48:03 +01:00
parent bd5eccb945
commit bf00a8ef7f
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -55,17 +55,14 @@ func GetStateIDs(
return *err
}
state, err := getState(ctx, request, rsAPI, roomID, eventID)
state, err := getStateIDs(ctx, request, rsAPI, roomID, eventID)
if err != nil {
return *err
}
stateEventIDs := getIDsFromEvent(state.StateEvents)
authEventIDs := getIDsFromEvent(state.AuthEvents)
return util.JSONResponse{Code: http.StatusOK, JSON: gomatrixserverlib.RespStateIDs{
StateEventIDs: stateEventIDs,
AuthEventIDs: authEventIDs,
StateEventIDs: state.StateEventIDs,
AuthEventIDs: state.AuthEventIDs,
},
}
}
@ -136,6 +133,50 @@ func getState(
}, nil
}
func getStateIDs(
ctx context.Context,
request *gomatrixserverlib.FederationRequest,
rsAPI api.RoomserverInternalAPI,
roomID string,
eventID string,
) (*gomatrixserverlib.RespStateIDs, *util.JSONResponse) {
event, resErr := fetchEvent(ctx, rsAPI, eventID)
if resErr != nil {
return nil, resErr
}
if event.RoomID() != roomID {
return nil, &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 nil, resErr
}
var response api.QueryStateAndAuthChainIDsResponse
err := rsAPI.QueryStateAndAuthChainIDs(
ctx,
&api.QueryStateAndAuthChainIDsRequest{
RoomID: roomID,
PrevEventIDs: []string{eventID},
},
&response,
)
if err != nil {
resErr := util.ErrorResponse(err)
return nil, &resErr
}
if !response.RoomExists {
return nil, &util.JSONResponse{Code: http.StatusNotFound, JSON: nil}
}
return &gomatrixserverlib.RespStateIDs{
StateEventIDs: response.StateEvents,
AuthEventIDs: response.AuthChainEvents,
}, nil
}
func getIDsFromEvent(events []*gomatrixserverlib.Event) []string {
IDs := make([]string, len(events))
for i := range events {