Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Add an experimental config option.
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed Aug 5, 2022
1 parent dfd921d commit e0ed95a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
2 changes: 2 additions & 0 deletions synapse/config/experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:

# 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)
Expand Down
38 changes: 26 additions & 12 deletions synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ def __init__(self, hs: "HomeServer"):

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,
Expand Down Expand Up @@ -2127,20 +2129,32 @@ async def _generate_room_entry(
)

# 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)

Expand Down
3 changes: 2 additions & 1 deletion synapse/rest/client/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,8 @@ async def encode_room(
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
Expand Down

0 comments on commit e0ed95a

Please sign in to comment.