From 7aa051958956232461766388f5b88d73c89ab3c5 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Mon, 10 Jun 2024 14:43:00 -0500 Subject: [PATCH] Incorporate `to_token` to filters --- synapse/handlers/sliding_sync.py | 12 ++++++++---- tests/handlers/test_sliding_sync.py | 5 +++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/synapse/handlers/sliding_sync.py b/synapse/handlers/sliding_sync.py index 08c6aadff6..e452c31cba 100644 --- a/synapse/handlers/sliding_sync.py +++ b/synapse/handlers/sliding_sync.py @@ -335,11 +335,8 @@ class SlidingSyncHandler: # Apply filters filtered_room_ids = room_id_set if list_config.filters is not None: - # TODO: To be absolutely correct, this could also take into account - # from/to tokens but some of the streams don't support looking back - # in time (like global account_data). filtered_room_ids = await self.filter_rooms( - sync_config.user, room_id_set, list_config.filters + sync_config.user, room_id_set, list_config.filters, to_token ) # TODO: Apply sorts sorted_room_ids = sorted(filtered_room_ids) @@ -618,9 +615,16 @@ class SlidingSyncHandler: user: UserID, room_id_set: AbstractSet[str], filters: SlidingSyncConfig.SlidingSyncList.Filters, + to_token: StreamToken, ) -> AbstractSet[str]: """ Filter rooms based on the sync request. + + Args: + user: User to filter rooms for + room_id_set: Set of room IDs to filter down + filters: Filters to apply + to_token: We filter based on the state of the room at this token """ user_id = user.to_string() diff --git a/tests/handlers/test_sliding_sync.py b/tests/handlers/test_sliding_sync.py index e0c8a031a2..a84d4553c6 100644 --- a/tests/handlers/test_sliding_sync.py +++ b/tests/handlers/test_sliding_sync.py @@ -1140,6 +1140,7 @@ class FilterRoomsTestCase(HomeserverTestCase): def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None: self.sliding_sync_handler = self.hs.get_sliding_sync_handler() self.store = self.hs.get_datastores().main + self.event_sources = hs.get_event_sources() def _create_dm_room( self, @@ -1213,6 +1214,8 @@ class FilterRoomsTestCase(HomeserverTestCase): invitee_tok=user2_tok, ) + after_rooms_token = self.event_sources.get_current_token() + # TODO: Better way to avoid the circular import? (see # https://github.com/element-hq/synapse/pull/17187#discussion_r1619492779) from synapse.handlers.sliding_sync import SlidingSyncConfig @@ -1225,6 +1228,7 @@ class FilterRoomsTestCase(HomeserverTestCase): SlidingSyncConfig.SlidingSyncList.Filters( is_dm=True, ), + after_rooms_token, ) ) @@ -1238,6 +1242,7 @@ class FilterRoomsTestCase(HomeserverTestCase): SlidingSyncConfig.SlidingSyncList.Filters( is_dm=False, ), + after_rooms_token, ) )