From d56296aa57b3ffb8f687c5cdcbaabd1a5e00c4f2 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Thu, 28 Jul 2022 14:55:38 -0400 Subject: [PATCH] Add a sync flag for unread thread notifications --- synapse/api/filtering.py | 7 +++++++ synapse/handlers/sync.py | 7 +++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/synapse/api/filtering.py b/synapse/api/filtering.py index b00714751956..355849475a78 100644 --- a/synapse/api/filtering.py +++ b/synapse/api/filtering.py @@ -84,6 +84,7 @@ "contains_url": {"type": "boolean"}, "lazy_load_members": {"type": "boolean"}, "include_redundant_members": {"type": "boolean"}, + "unread_thread_notifications": {"type": "boolean"}, # Include or exclude events with the provided labels. # cf https://github.com/matrix-org/matrix-doc/pull/2326 "org.matrix.labels": {"type": "array", "items": {"type": "string"}}, @@ -240,6 +241,9 @@ def lazy_load_members(self) -> bool: def include_redundant_members(self) -> bool: return self._room_state_filter.include_redundant_members + def unread_thread_notifications(self) -> bool: + return self._room_timeline_filter.unread_thread_notifications + async def filter_presence( self, events: Iterable[UserPresenceState] ) -> List[UserPresenceState]: @@ -304,6 +308,9 @@ def __init__(self, hs: "HomeServer", filter_json: JsonDict): self.include_redundant_members = filter_json.get( "include_redundant_members", False ) + self.unread_thread_notifications = filter_json.get( + "unread_thread_notifications", False + ) self.types = filter_json.get("types", None) self.not_types = filter_json.get("not_types", []) diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py index 25c98e5cf43a..2da618e7cb82 100644 --- a/synapse/handlers/sync.py +++ b/synapse/handlers/sync.py @@ -2133,8 +2133,11 @@ async def _generate_room_entry( highlight_count = notifs.highlight_count unread_count = notifs.unread_count - # XXX Check the sync configuration. - if self._msc3773_enabled: + # Check the sync configuration. + if ( + self._msc3773_enabled + and sync_config.filter_collection.unread_thread_notifications() + ): # And add info for each thread. room_sync.unread_thread_notifications = { thread_id: {