Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/16909.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add experimental config option to not send device list updates for specific users.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me think that the config should be under experimental_features. Should it be, even though it's not an MSC?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ermh, good Q, my gut says no TBH, but 🤷

Copy link
Copy Markdown
Member

@anoadragon453 anoadragon453 Feb 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may reword the changelog to say "temporary" or "hidden" option instead then, as "experimental" sounds like it should live under experimental_features, though I understand not expanding the scope of that config option past MSCs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...although, when attempting to insert those suggestions myself into the changelog, neither are as good as experimental.

I'm happy to keep it as "experimental", but I'd like to ensure we don't forget about it and never document it. Could you make a quick issue to come back whether we want to keep and document/remove it in the future?

8 changes: 8 additions & 0 deletions synapse/config/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,14 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:

self.inhibit_user_in_use_error = config.get("inhibit_user_in_use_error", False)

# List of user IDs not to send out device list updates for when they
# register new devices. This is useful to handle bot accounts.
#
# Note: This will still send out device list updates if the device is
# later updated, e.g. end to end keys are added.
dont_notify_new_devices_for = config.get("dont_notify_new_devices_for", [])
self.dont_notify_new_devices_for = frozenset(dont_notify_new_devices_for)

def generate_config_section(
self, generate_secrets: bool = False, **kwargs: Any
) -> str:
Expand Down
13 changes: 11 additions & 2 deletions synapse/handlers/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@ def __init__(self, hs: "HomeServer"):
self._storage_controllers = hs.get_storage_controllers()
self.db_pool = hs.get_datastores().main.db_pool

self._dont_notify_new_devices_for = (
hs.config.registration.dont_notify_new_devices_for
)

self.device_list_updater = DeviceListUpdater(hs, self)

federation_registry = hs.get_federation_registry()
Expand Down Expand Up @@ -505,6 +509,9 @@ async def check_device_registered(

self._check_device_name_length(initial_device_display_name)

# Check if we should send out device lists updates for this new device.
notify = user_id not in self._dont_notify_new_devices_for

if device_id is not None:
new_device = await self.store.store_device(
user_id=user_id,
Expand All @@ -514,7 +521,8 @@ async def check_device_registered(
auth_provider_session_id=auth_provider_session_id,
)
if new_device:
await self.notify_device_update(user_id, [device_id])
if notify:
await self.notify_device_update(user_id, [device_id])
return device_id

# if the device id is not specified, we'll autogen one, but loop a few
Expand All @@ -530,7 +538,8 @@ async def check_device_registered(
auth_provider_session_id=auth_provider_session_id,
)
if new_device:
await self.notify_device_update(user_id, [new_device_id])
if notify:
await self.notify_device_update(user_id, [new_device_id])
return new_device_id
attempts += 1

Expand Down