aboutsummaryrefslogtreecommitdiff
path: root/syncapi/sync
diff options
context:
space:
mode:
authorKegsay <kegan@matrix.org>2020-06-26 15:34:41 +0100
committerGitHub <noreply@github.com>2020-06-26 15:34:41 +0100
commit1ad7219e4b6c71f64e4d44db17a6a8d729e6198a (patch)
treec13db3fd184c0c9bd7d879793be7e5aba2066121 /syncapi/sync
parent164057a3be1e666d6fb68398d616da9a8a665a18 (diff)
Implement /sync `limited` and read timeline limit from stored filters (#1168)
* Move filter table to syncapi where it is used * Implement /sync `limited` and read timeline limit from stored filters We now fully handle `room.timeline.limit` filters (in-line + stored) and return the right value for `limited` syncs. * Update whitelist * Default to the default timeline limit if it's unset, also strip the extra event correctly * Update whitelist
Diffstat (limited to 'syncapi/sync')
-rw-r--r--syncapi/sync/notifier_test.go2
-rw-r--r--syncapi/sync/request.go33
-rw-r--r--syncapi/sync/requestpool.go2
3 files changed, 26 insertions, 11 deletions
diff --git a/syncapi/sync/notifier_test.go b/syncapi/sync/notifier_test.go
index ecc4fcbf..f2a368ec 100644
--- a/syncapi/sync/notifier_test.go
+++ b/syncapi/sync/notifier_test.go
@@ -363,7 +363,7 @@ func newTestSyncRequest(userID, deviceID string, since types.StreamingToken) syn
timeout: 1 * time.Minute,
since: &since,
wantFullState: false,
- limit: defaultTimelineLimit,
+ limit: DefaultTimelineLimit,
log: util.GetLogger(context.TODO()),
ctx: context.TODO(),
}
diff --git a/syncapi/sync/request.go b/syncapi/sync/request.go
index 5dd92c85..41b18aa1 100644
--- a/syncapi/sync/request.go
+++ b/syncapi/sync/request.go
@@ -21,14 +21,16 @@ import (
"strconv"
"time"
+ "github.com/matrix-org/dendrite/syncapi/storage"
"github.com/matrix-org/dendrite/syncapi/types"
userapi "github.com/matrix-org/dendrite/userapi/api"
+ "github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util"
log "github.com/sirupsen/logrus"
)
const defaultSyncTimeout = time.Duration(0)
-const defaultTimelineLimit = 20
+const DefaultTimelineLimit = 20
type filter struct {
Room struct {
@@ -49,7 +51,7 @@ type syncRequest struct {
log *log.Entry
}
-func newSyncRequest(req *http.Request, device userapi.Device) (*syncRequest, error) {
+func newSyncRequest(req *http.Request, device userapi.Device, syncDB storage.Database) (*syncRequest, error) {
timeout := getTimeout(req.URL.Query().Get("timeout"))
fullState := req.URL.Query().Get("full_state")
wantFullState := fullState != "" && fullState != "false"
@@ -66,15 +68,28 @@ func newSyncRequest(req *http.Request, device userapi.Device) (*syncRequest, err
tok := types.NewStreamToken(0, 0)
since = &tok
}
- timelineLimit := defaultTimelineLimit
+ 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
+ if filterQuery != "" {
+ if 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
+ }
+ } else {
+ // attempt to load the filter ID
+ localpart, _, err := gomatrixserverlib.SplitID('@', device.UserID)
+ if err != nil {
+ util.GetLogger(req.Context()).WithError(err).Error("gomatrixserverlib.SplitID failed")
+ return nil, err
+ }
+ f, err := syncDB.GetFilter(req.Context(), localpart, filterQuery)
+ if err == nil {
+ timelineLimit = f.Room.Timeline.Limit
+ }
}
}
// TODO: Additional query params: set_presence, filter
diff --git a/syncapi/sync/requestpool.go b/syncapi/sync/requestpool.go
index 743c63a6..196d446a 100644
--- a/syncapi/sync/requestpool.go
+++ b/syncapi/sync/requestpool.go
@@ -49,7 +49,7 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *userapi.
var syncData *types.Response
// Extract values from request
- syncReq, err := newSyncRequest(req, *device)
+ syncReq, err := newSyncRequest(req, *device, rp.db)
if err != nil {
return util.JSONResponse{
Code: http.StatusBadRequest,