diff --git a/src/github.com/matrix-org/dendrite/syncapi/storage/filtering.go b/src/github.com/matrix-org/dendrite/syncapi/storage/filtering.go new file mode 100644 index 000000000..21ab25877 --- /dev/null +++ b/src/github.com/matrix-org/dendrite/syncapi/storage/filtering.go @@ -0,0 +1,48 @@ +// Copyright 2017 Vector Creations Ltd +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package storage + +import ( + "github.com/matrix-org/gomatrix" +) + +func isRoomFiltered(roomID string, filter *gomatrix.Filter, filterPart *gomatrix.FilterPart) bool { + if filter != nil { + if filter.Room.Rooms != nil && !hasValue(roomID, filter.Room.Rooms) { + return true + } + if filter.Room.NotRooms != nil && hasValue(roomID, filter.Room.NotRooms) { + return true + } + } + if filterPart != nil { + if filterPart.Rooms != nil && !hasValue(roomID, filterPart.Rooms) { + return true + } + if filterPart.NotRooms != nil && hasValue(roomID, filterPart.NotRooms) { + return true + } + } + return false +} + +func hasValue(value string, list []string) bool { + for i := range list { + if list[i] == value { + return true + } + } + return false +} 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 d132cefd6..36b10e156 100644 --- a/src/github.com/matrix-org/dendrite/syncapi/storage/syncserver.go +++ b/src/github.com/matrix-org/dendrite/syncapi/storage/syncserver.go @@ -245,9 +245,11 @@ func (d *SyncServerDatabase) IncrementalSync( res := types.NewResponse(toPos) for _, delta := range deltas { - err = d.addRoomDeltaToResponse(ctx, &device, txn, fromPos, toPos, delta, filter, res) - if err != nil { - return nil, err + if !isRoomFiltered(delta.roomID, filter, &filter.Room.Timeline) { + err = d.addRoomDeltaToResponse(ctx, &device, txn, fromPos, toPos, delta, filter, res) + if err != nil { + return nil, err + } } } @@ -295,7 +297,7 @@ func (d *SyncServerDatabase) CompleteSync( jr := types.NewJoinResponse() //Join response should contain events only if room isn't filtered - if !isRoomFiltered(filter, roomID) { + if !isRoomFiltered(roomID, filter, &filter.Room.Timeline) { // Timeline events var recentStreamEvents []streamEvent var limited bool diff --git a/src/github.com/matrix-org/dendrite/syncapi/sync/request.go b/src/github.com/matrix-org/dendrite/syncapi/sync/request.go index 92bc79e3e..42494b9b5 100644 --- a/src/github.com/matrix-org/dendrite/syncapi/sync/request.go +++ b/src/github.com/matrix-org/dendrite/syncapi/sync/request.go @@ -31,7 +31,6 @@ import ( ) const defaultSyncTimeout = time.Duration(30) * time.Second -const defaultTimelineLimit = 20 // syncRequest represents a /sync request, with sensible defaults/sanity checks applied. type syncRequest struct { diff --git a/vendor/src/github.com/matrix-org/gomatrix/filter.go b/vendor/src/github.com/matrix-org/gomatrix/filter.go index 43ff1c773..820f44f0c 100644 --- a/vendor/src/github.com/matrix-org/gomatrix/filter.go +++ b/vendor/src/github.com/matrix-org/gomatrix/filter.go @@ -74,7 +74,7 @@ func defaultFilterPart() FilterPart { return FilterPart{ NotRooms: nil, Rooms: nil, - Limit: 100, //TODO check this on synapse + Limit: 20, NotSenders: nil, NotTypes: nil, Senders: nil,