summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erikj@element.io>2024-02-13 13:23:03 +0000
committerGitHub <noreply@github.com>2024-02-13 13:23:03 +0000
commit01910b981f332a4ccf093bcae9f8e4b7dd3cbc13 (patch)
tree2e1bb4149a26d5406c10992d67b9bb228e70662c
parentBump pygithub from 2.1.1 to 2.2.0 (#16902) (diff)
downloadsynapse-01910b981f332a4ccf093bcae9f8e4b7dd3cbc13.tar.xz
Add a config to not send out device list updates for specific users (#16909)
List of users not to send out device list updates for when they register
new devices. This is useful to handle bot accounts.

This is undocumented as its mostly a hack to test on matrix.org.

Note: This will still send out device list updates if the device is
later updated, e.g. end to end keys are added.
Diffstat (limited to '')
-rw-r--r--changelog.d/16909.misc1
-rw-r--r--synapse/config/registration.py8
-rw-r--r--synapse/handlers/device.py13
3 files changed, 20 insertions, 2 deletions
diff --git a/changelog.d/16909.misc b/changelog.d/16909.misc
new file mode 100644
index 0000000000..f958936584
--- /dev/null
+++ b/changelog.d/16909.misc
@@ -0,0 +1 @@
+Add experimental config option to not send device list updates for specific users.
diff --git a/synapse/config/registration.py b/synapse/config/registration.py
index 9e2b1f3de1..3fe0f050cd 100644
--- a/synapse/config/registration.py
+++ b/synapse/config/registration.py
@@ -237,6 +237,14 @@ class RegistrationConfig(Config):
 
         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:
diff --git a/synapse/handlers/device.py b/synapse/handlers/device.py
index 9062fac91a..67953a3ed9 100644
--- a/synapse/handlers/device.py
+++ b/synapse/handlers/device.py
@@ -429,6 +429,10 @@ class DeviceHandler(DeviceWorkerHandler):
         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()
@@ -505,6 +509,9 @@ class DeviceHandler(DeviceWorkerHandler):
 
         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,
@@ -514,7 +521,8 @@ class DeviceHandler(DeviceWorkerHandler):
                 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
@@ -530,7 +538,8 @@ class DeviceHandler(DeviceWorkerHandler):
                 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