|
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, |
@@ -1288,7 +1291,7 @@ async def _find_missing_partial_state_memberships( |
1288 | 1291 |
|
1289 | 1292 | async def unread_notifs_for_room_id( |
1290 | 1293 | self, room_id: str, sync_config: SyncConfig |
1291 | | - ) -> NotifCounts: |
| 1294 | + ) -> RoomNotifCounts: |
1292 | 1295 | with Measure(self.clock, "unread_notifs_for_room_id"): |
1293 | 1296 |
|
1294 | 1297 | return await self.store.get_unread_event_push_actions_by_room_for_user( |
@@ -2353,17 +2356,44 @@ async def _generate_room_entry( |
2353 | 2356 | ephemeral=ephemeral, |
2354 | 2357 | account_data=account_data_events, |
2355 | 2358 | unread_notifications=unread_notifications, |
| 2359 | + unread_thread_notifications={}, |
2356 | 2360 | summary=summary, |
2357 | 2361 | unread_count=0, |
2358 | 2362 | ) |
2359 | 2363 |
|
2360 | 2364 | if room_sync or always_include: |
2361 | 2365 | notifs = await self.unread_notifs_for_room_id(room_id, sync_config) |
2362 | 2366 |
|
2363 | | - unread_notifications["notification_count"] = notifs.notify_count |
2364 | | - unread_notifications["highlight_count"] = notifs.highlight_count |
| 2367 | + # Notifications for the main timeline. |
| 2368 | + notify_count = notifs.main_timeline.notify_count |
| 2369 | + highlight_count = notifs.main_timeline.highlight_count |
| 2370 | + unread_count = notifs.main_timeline.unread_count |
2365 | 2371 |
|
2366 | | - room_sync.unread_count = notifs.unread_count |
| 2372 | + # Check the sync configuration. |
| 2373 | + if ( |
| 2374 | + self._msc3773_enabled |
| 2375 | + and sync_config.filter_collection.unread_thread_notifications() |
| 2376 | + ): |
| 2377 | + # And add info for each thread. |
| 2378 | + room_sync.unread_thread_notifications = { |
| 2379 | + thread_id: { |
| 2380 | + "notification_count": thread_notifs.notify_count, |
| 2381 | + "highlight_count": thread_notifs.highlight_count, |
| 2382 | + } |
| 2383 | + for thread_id, thread_notifs in notifs.threads.items() |
| 2384 | + if thread_id is not None |
| 2385 | + } |
| 2386 | + |
| 2387 | + else: |
| 2388 | + # Combine the unread counts for all threads and main timeline. |
| 2389 | + for thread_notifs in notifs.threads.values(): |
| 2390 | + notify_count += thread_notifs.notify_count |
| 2391 | + highlight_count += thread_notifs.highlight_count |
| 2392 | + unread_count += thread_notifs.unread_count |
| 2393 | + |
| 2394 | + unread_notifications["notification_count"] = notify_count |
| 2395 | + unread_notifications["highlight_count"] = highlight_count |
| 2396 | + room_sync.unread_count = unread_count |
2367 | 2397 |
|
2368 | 2398 | sync_result_builder.joined.append(room_sync) |
2369 | 2399 |
|
|
0 commit comments