aboutsummaryrefslogtreecommitdiff
path: root/syncapi/sync/request.go
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/request.go
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/request.go')
-rw-r--r--syncapi/sync/request.go33
1 files changed, 24 insertions, 9 deletions
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