|
40 | 40 | from synapse.logging.context import current_context |
41 | 41 | from synapse.logging.opentracing import SynapseTags, log_kv, set_tag, start_active_span |
42 | 42 | from synapse.push.clientformat import format_push_rules_for_user |
43 | | -from synapse.storage.databases.main.event_push_actions import NotifCounts |
| 43 | +from synapse.storage.databases.main.event_push_actions import RoomNotifCounts |
44 | 44 | from synapse.storage.roommember import MemberSummary |
45 | 45 | from synapse.storage.state import StateFilter |
46 | 46 | from synapse.types import ( |
@@ -128,6 +128,7 @@ class JoinedSyncResult: |
128 | 128 | ephemeral: List[JsonDict] |
129 | 129 | account_data: List[JsonDict] |
130 | 130 | unread_notifications: JsonDict |
| 131 | + unread_thread_notifications: JsonDict |
131 | 132 | summary: Optional[JsonDict] |
132 | 133 | unread_count: int |
133 | 134 |
|
@@ -278,6 +279,8 @@ def __init__(self, hs: "HomeServer"): |
278 | 279 |
|
279 | 280 | self.rooms_to_exclude = hs.config.server.rooms_to_exclude_from_sync |
280 | 281 |
|
| 282 | + self._msc3773_enabled = hs.config.experimental.msc3773_enabled |
| 283 | + |
281 | 284 | async def wait_for_sync_for_user( |
282 | 285 | self, |
283 | 286 | requester: Requester, |
@@ -1272,7 +1275,7 @@ async def _find_missing_partial_state_memberships( |
1272 | 1275 |
|
1273 | 1276 | async def unread_notifs_for_room_id( |
1274 | 1277 | self, room_id: str, sync_config: SyncConfig |
1275 | | - ) -> NotifCounts: |
| 1278 | + ) -> RoomNotifCounts: |
1276 | 1279 | with Measure(self.clock, "unread_notifs_for_room_id"): |
1277 | 1280 |
|
1278 | 1281 | return await self.store.get_unread_event_push_actions_by_room_for_user( |
@@ -2343,17 +2346,44 @@ async def _generate_room_entry( |
2343 | 2346 | ephemeral=ephemeral, |
2344 | 2347 | account_data=account_data_events, |
2345 | 2348 | unread_notifications=unread_notifications, |
| 2349 | + unread_thread_notifications={}, |
2346 | 2350 | summary=summary, |
2347 | 2351 | unread_count=0, |
2348 | 2352 | ) |
2349 | 2353 |
|
2350 | 2354 | if room_sync or always_include: |
2351 | 2355 | notifs = await self.unread_notifs_for_room_id(room_id, sync_config) |
2352 | 2356 |
|
2353 | | - unread_notifications["notification_count"] = notifs.notify_count |
2354 | | - unread_notifications["highlight_count"] = notifs.highlight_count |
| 2357 | + # Notifications for the main timeline. |
| 2358 | + notify_count = notifs.main_timeline.notify_count |
| 2359 | + highlight_count = notifs.main_timeline.highlight_count |
| 2360 | + unread_count = notifs.main_timeline.unread_count |
2355 | 2361 |
|
2356 | | - room_sync.unread_count = notifs.unread_count |
| 2362 | + # Check the sync configuration. |
| 2363 | + if ( |
| 2364 | + self._msc3773_enabled |
| 2365 | + and sync_config.filter_collection.unread_thread_notifications() |
| 2366 | + ): |
| 2367 | + # And add info for each thread. |
| 2368 | + room_sync.unread_thread_notifications = { |
| 2369 | + thread_id: { |
| 2370 | + "notification_count": thread_notifs.notify_count, |
| 2371 | + "highlight_count": thread_notifs.highlight_count, |
| 2372 | + } |
| 2373 | + for thread_id, thread_notifs in notifs.threads.items() |
| 2374 | + if thread_id is not None |
| 2375 | + } |
| 2376 | + |
| 2377 | + else: |
| 2378 | + # Combine the unread counts for all threads and main timeline. |
| 2379 | + for thread_notifs in notifs.threads.values(): |
| 2380 | + notify_count += thread_notifs.notify_count |
| 2381 | + highlight_count += thread_notifs.highlight_count |
| 2382 | + unread_count += thread_notifs.unread_count |
| 2383 | + |
| 2384 | + unread_notifications["notification_count"] = notify_count |
| 2385 | + unread_notifications["highlight_count"] = highlight_count |
| 2386 | + room_sync.unread_count = unread_count |
2357 | 2387 |
|
2358 | 2388 | sync_result_builder.joined.append(room_sync) |
2359 | 2389 |
|
|
0 commit comments