mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-04-04 11:03:39 +00:00
Wire in new code
This commit is contained in:
parent
bd5eccb945
commit
bf00a8ef7f
1 changed files with 47 additions and 6 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue