From dbd52ef982ea9ae790b724865c682da3efb41a72 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Thu, 21 Sep 2017 19:22:19 +0200 Subject: [PATCH] Doc --- .../dendrite/syncapi/storage/syncserver.go | 3 +++ .../dendrite/syncapi/sync/requestpool.go | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/github.com/matrix-org/dendrite/syncapi/storage/syncserver.go b/src/github.com/matrix-org/dendrite/syncapi/storage/syncserver.go index d65ea8ecf..383e86da2 100644 --- a/src/github.com/matrix-org/dendrite/syncapi/storage/syncserver.go +++ b/src/github.com/matrix-org/dendrite/syncapi/storage/syncserver.go @@ -162,6 +162,9 @@ func (d *SyncServerDatabase) GetStateEvent( return d.roomstate.selectStateEvent(ctx, evType, roomID, stateKey) } +// GetStateEventsForRoom fetches the state events for a given room. +// Returns an empty slice if no state events could be found for this room. +// Returns an error if there was an issue with the retrieval. func (d *SyncServerDatabase) GetStateEventsForRoom( ctx context.Context, roomID string, ) (stateEvents []gomatrixserverlib.Event, err error) { diff --git a/src/github.com/matrix-org/dendrite/syncapi/sync/requestpool.go b/src/github.com/matrix-org/dendrite/syncapi/sync/requestpool.go index c0524ee05..ad879754d 100644 --- a/src/github.com/matrix-org/dendrite/syncapi/sync/requestpool.go +++ b/src/github.com/matrix-org/dendrite/syncapi/sync/requestpool.go @@ -107,22 +107,31 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *authtype } } -type stateEventInResp struct { +type stateEventInStateResp struct { gomatrixserverlib.ClientEvent PrevContent json.RawMessage `json:"prev_content,omitempty"` ReplacesState string `json:"replaces_state,omitempty"` } +// OnIncomingStateRequest is called when a client makes a /rooms/{roomID}/state +// request. It will fetch all the state events from the specified room and will +// append the necessary keys to them if applicable before returning them. +// Returns an error if something went wrong in the process. +// TODO: Check if the user is in the room. If not, check if the room's history +// is publicly visible. Current behaviour is returning an empty array if the +// user cannot see the room's history. func (rp *RequestPool) OnIncomingStateRequest(req *http.Request, roomID string) util.JSONResponse { stateEvents, err := rp.db.GetStateEventsForRoom(req.Context(), roomID) if err != nil { return httputil.LogThenError(req, err) } - resp := []stateEventInResp{} + resp := []stateEventInStateResp{} // Fill the prev_content and replaces_state keys if necessary for _, event := range stateEvents { - stateEvent := stateEventInResp{ClientEvent: gomatrixserverlib.ToClientEvent(event, gomatrixserverlib.FormatAll)} + stateEvent := stateEventInStateResp{ + ClientEvent: gomatrixserverlib.ToClientEvent(event, gomatrixserverlib.FormatAll) + } var prevEventRef types.PrevEventRef fmt.Println(len(event.Unsigned())) if len(event.Unsigned()) > 0 {