diff options
Diffstat (limited to 'synapse')
-rw-r--r-- | synapse/config/experimental.py | 2 | ||||
-rw-r--r-- | synapse/handlers/sync.py | 38 | ||||
-rw-r--r-- | synapse/rest/client/sync.py | 3 |
3 files changed, 30 insertions, 13 deletions
diff --git a/synapse/config/experimental.py b/synapse/config/experimental.py index c2ecd977cd..0c28182799 100644 --- a/synapse/config/experimental.py +++ b/synapse/config/experimental.py @@ -84,6 +84,8 @@ class ExperimentalConfig(Config): # MSC3772: A push rule for mutual relations. self.msc3772_enabled: bool = experimental.get("msc3772_enabled", False) + # MSC3773: Thread notifications + self.msc3773_enabled: bool = experimental.get("msc3773_enabled", False) # MSC3715: dir param on /relations. self.msc3715_enabled: bool = experimental.get("msc3715_enabled", False) diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py index 94af490cc6..25c98e5cf4 100644 --- a/synapse/handlers/sync.py +++ b/synapse/handlers/sync.py @@ -266,6 +266,8 @@ class SyncHandler: self.rooms_to_exclude = hs.config.server.rooms_to_exclude_from_sync + self._msc3773_enabled = hs.config.experimental.msc3773_enabled + async def wait_for_sync_for_user( self, requester: Requester, @@ -2127,20 +2129,32 @@ class SyncHandler: ) # Notifications for the main timeline. - unread_notifications["notification_count"] = notifs.notify_count - unread_notifications["highlight_count"] = notifs.highlight_count + notify_count = notifs.notify_count + highlight_count = notifs.highlight_count + unread_count = notifs.unread_count + + # XXX Check the sync configuration. + if self._msc3773_enabled: + # And add info for each thread. + room_sync.unread_thread_notifications = { + thread_id: { + "notification_count": tnotifs.notify_count, + "highlight_count": tnotifs.highlight_count, + } + for thread_id, tnotifs in thread_notifs.items() + if thread_id is not None + } - room_sync.unread_count = notifs.unread_count + else: + # Combine the unread counts for all threads and main timeline. + for tnotifs in thread_notifs.values(): + notify_count += tnotifs.notify_count + highlight_count += tnotifs.highlight_count + unread_count += tnotifs.unread_count - # And add info for each thread. - room_sync.unread_thread_notifications = { - thread_id: { - "notification_count": thread_notifs.notify_count, - "highlight_count": thread_notifs.highlight_count, - } - for thread_id, thread_notifs in thread_notifs.items() - if thread_id is not None - } + unread_notifications["notification_count"] = notify_count + unread_notifications["highlight_count"] = highlight_count + room_sync.unread_count = unread_count sync_result_builder.joined.append(room_sync) diff --git a/synapse/rest/client/sync.py b/synapse/rest/client/sync.py index 16b0bc9f04..612a44db68 100644 --- a/synapse/rest/client/sync.py +++ b/synapse/rest/client/sync.py @@ -509,7 +509,8 @@ class SyncRestServlet(RestServlet): ephemeral_events = room.ephemeral result["ephemeral"] = {"events": ephemeral_events} result["unread_notifications"] = room.unread_notifications - result["unread_thread_notifications"] = room.unread_thread_notifications + if room.unread_thread_notifications: + result["unread_thread_notifications"] = room.unread_thread_notifications result["summary"] = room.summary if self._msc2654_enabled: result["org.matrix.msc2654.unread_count"] = room.unread_count |