From 6091bf044ff41e9f248b1077d5b05f1a4c694412 Mon Sep 17 00:00:00 2001 From: Kegsay Date: Wed, 20 May 2020 17:30:03 +0100 Subject: [PATCH] sytest: Add remaining backfill tests (#1052) One failed because of `null` instead of `[]` in HTTP responses. One failed because we hadn't implemented in-line filter limits! --- federationapi/routing/backfill.go | 2 +- syncapi/sync/request.go | 22 +++++++++++++++++++++- syncapi/sync/requestpool.go | 1 + sytest-whitelist | 2 ++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/federationapi/routing/backfill.go b/federationapi/routing/backfill.go index 1f46b240f..0d3893de3 100644 --- a/federationapi/routing/backfill.go +++ b/federationapi/routing/backfill.go @@ -102,7 +102,7 @@ func Backfill( } } - var eventJSONs []json.RawMessage + eventJSONs := []json.RawMessage{} for _, e := range gomatrixserverlib.ReverseTopologicalOrdering( evs, gomatrixserverlib.TopologicalOrderByPrevEvents, diff --git a/syncapi/sync/request.go b/syncapi/sync/request.go index 66663cf0a..c7796b561 100644 --- a/syncapi/sync/request.go +++ b/syncapi/sync/request.go @@ -16,6 +16,7 @@ package sync import ( "context" + "encoding/json" "net/http" "strconv" "time" @@ -30,6 +31,14 @@ import ( const defaultSyncTimeout = time.Duration(0) const defaultTimelineLimit = 20 +type filter struct { + Room struct { + Timeline struct { + Limit *int `json:"limit"` + } `json:"timeline"` + } `json:"room"` +} + // syncRequest represents a /sync request, with sensible defaults/sanity checks applied. type syncRequest struct { ctx context.Context @@ -54,6 +63,17 @@ func newSyncRequest(req *http.Request, device authtypes.Device) (*syncRequest, e } since = &tok } + timelineLimit := defaultTimelineLimit + // TODO: read from stored filters too + filterQuery := req.URL.Query().Get("filter") + if filterQuery != "" && filterQuery[0] == '{' { + // attempt to parse the timeline limit at least + var f filter + err := json.Unmarshal([]byte(filterQuery), &f) + if err == nil && f.Room.Timeline.Limit != nil { + timelineLimit = *f.Room.Timeline.Limit + } + } // TODO: Additional query params: set_presence, filter return &syncRequest{ ctx: req.Context(), @@ -61,7 +81,7 @@ func newSyncRequest(req *http.Request, device authtypes.Device) (*syncRequest, e timeout: timeout, since: since, wantFullState: wantFullState, - limit: defaultTimelineLimit, // TODO: read from filter + limit: timelineLimit, log: util.GetLogger(req.Context()), }, nil } diff --git a/syncapi/sync/requestpool.go b/syncapi/sync/requestpool.go index 6e0f44e9a..82ce283b6 100644 --- a/syncapi/sync/requestpool.go +++ b/syncapi/sync/requestpool.go @@ -59,6 +59,7 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *authtype "userID": userID, "since": syncReq.since, "timeout": syncReq.timeout, + "limit": syncReq.limit, }) currPos := rp.notifier.CurrentPosition() diff --git a/sytest-whitelist b/sytest-whitelist index 2e8205dcd..d5b4feaf6 100644 --- a/sytest-whitelist +++ b/sytest-whitelist @@ -281,3 +281,5 @@ An event which redacts itself should be ignored A pair of events which redact each other should be ignored Outbound federation can backfill events Inbound federation can backfill events +Backfill checks the events requested belong to the room +Backfilled events whose prev_events are in a different room do not allow cross-room back-pagination