From c67953748def5d549eb978ad0e9e72fe6ce32b6f Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 13 Nov 2018 10:34:38 +0000 Subject: [PATCH] Add thread_id to filter --- synapse/api/filtering.py | 5 +++++ synapse/rest/client/v1/room.py | 5 +++++ synapse/storage/stream.py | 16 ++++++++++++++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/synapse/api/filtering.py b/synapse/api/filtering.py index 677c0bdd4c..77f826c19d 100644 --- a/synapse/api/filtering.py +++ b/synapse/api/filtering.py @@ -120,6 +120,9 @@ ROOM_EVENT_FILTER_SCHEMA = { "include_redundant_members": { "type": "boolean" }, + "thread_id": { + "type": "number", + } } } @@ -331,6 +334,8 @@ class Filter(object): self.contains_url = self.filter_json.get("contains_url", None) + self.thread_id = self.filter_json.get("thread_id", None) + def filters_all_types(self): return "*" in self.not_types diff --git a/synapse/rest/client/v1/room.py b/synapse/rest/client/v1/room.py index fcfe7857f6..259c9712c6 100644 --- a/synapse/rest/client/v1/room.py +++ b/synapse/rest/client/v1/room.py @@ -471,6 +471,11 @@ class RoomMessageListRestServlet(ClientV1RestServlet): event_filter = Filter(json.loads(filter_json)) else: event_filter = None + + logger.info("filter_bytes: %s", filter_bytes) + logger.info("Event filter: %s", event_filter) + if event_filter: + logger.info("Event filter: %s", event_filter.thread_id) msgs = yield self.pagination_handler.get_messages( room_id=room_id, requester=requester, diff --git a/synapse/storage/stream.py b/synapse/storage/stream.py index d6cfdba519..27457d444b 100644 --- a/synapse/storage/stream.py +++ b/synapse/storage/stream.py @@ -149,7 +149,13 @@ def filter_to_clause(event_filter): clauses.append("contains_url = ?") args.append(event_filter.contains_url) - return " AND ".join(clauses), args + if event_filter.thread_id is not None: + clauses.append("thread_id = ?") + args.append(event_filter.thread_id) + + filter = " AND ".join(clauses), args + + return filter class StreamWorkerStore(EventsWorkerStore, SQLBaseStore): @@ -741,6 +747,11 @@ class StreamWorkerStore(EventsWorkerStore, SQLBaseStore): filter_clause, filter_args = filter_to_clause(event_filter) + logger.info("event_filter: %s", event_filter) + if event_filter is not None: + logger.info("event_filter: %s", event_filter.thread_id) + logger.info("Paginating with filter: %s", filter_clause) + if filter_clause: bounds += " AND " + filter_clause args.extend(filter_args) @@ -808,7 +819,8 @@ class StreamWorkerStore(EventsWorkerStore, SQLBaseStore): rows, token = yield self.runInteraction( "paginate_room_events", self._paginate_room_events_txn, - room_id, from_key, to_key, direction, limit, event_filter, + room_id, from_key, to_key, direction, limit, + event_filter=event_filter, ) events = yield self._get_events(