diff options
author | Eric Eastwood <eric.eastwood@beta.gouv.fr> | 2024-06-17 12:06:18 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-17 12:06:18 -0500 |
commit | a5485437cf8006b80345f2e0af6e233881e9de21 (patch) | |
tree | 823b380e636827f851746513b05a4e4f8e25cc47 /synapse/handlers/sliding_sync.py | |
parent | Add `stream_ordering` sort to Sliding Sync `/sync` (#17293) (diff) | |
download | synapse-a5485437cf8006b80345f2e0af6e233881e9de21.tar.xz |
Add `is_encrypted` filtering to Sliding Sync `/sync` (#17281)
Based on [MSC3575](https://github.com/matrix-org/matrix-spec-proposals/pull/3575): Sliding Sync
Diffstat (limited to 'synapse/handlers/sliding_sync.py')
-rw-r--r-- | synapse/handlers/sliding_sync.py | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/synapse/handlers/sliding_sync.py b/synapse/handlers/sliding_sync.py index b84cf67f7d..16d94925f5 100644 --- a/synapse/handlers/sliding_sync.py +++ b/synapse/handlers/sliding_sync.py @@ -22,7 +22,7 @@ from typing import TYPE_CHECKING, Dict, List, Optional, Tuple from immutabledict import immutabledict -from synapse.api.constants import AccountDataTypes, Membership +from synapse.api.constants import AccountDataTypes, EventTypes, Membership from synapse.events import EventBase from synapse.storage.roommember import RoomsForUser from synapse.types import ( @@ -33,6 +33,7 @@ from synapse.types import ( UserID, ) from synapse.types.handlers import OperationType, SlidingSyncConfig, SlidingSyncResult +from synapse.types.state import StateFilter if TYPE_CHECKING: from synapse.server import HomeServer @@ -85,6 +86,7 @@ class SlidingSyncHandler: def __init__(self, hs: "HomeServer"): self.clock = hs.get_clock() self.store = hs.get_datastores().main + self.storage_controllers = hs.get_storage_controllers() self.auth_blocking = hs.get_auth_blocking() self.notifier = hs.get_notifier() self.event_sources = hs.get_event_sources() @@ -570,8 +572,26 @@ class SlidingSyncHandler: if filters.spaces: raise NotImplementedError() - if filters.is_encrypted: - raise NotImplementedError() + # Filter for encrypted rooms + if filters.is_encrypted is not None: + # Make a copy so we don't run into an error: `Set changed size during + # iteration`, when we filter out and remove items + for room_id in list(filtered_room_id_set): + state_at_to_token = await self.storage_controllers.state.get_state_at( + room_id, + to_token, + state_filter=StateFilter.from_types( + [(EventTypes.RoomEncryption, "")] + ), + ) + is_encrypted = state_at_to_token.get((EventTypes.RoomEncryption, "")) + + # If we're looking for encrypted rooms, filter out rooms that are not + # encrypted and vice versa + if (filters.is_encrypted and not is_encrypted) or ( + not filters.is_encrypted and is_encrypted + ): + filtered_room_id_set.remove(room_id) if filters.is_invite: raise NotImplementedError() |