From d1ec44a862dc620934848069e416036dd0e67107 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Tue, 3 Jan 2023 15:04:37 +0000 Subject: [PATCH 1/6] Add an experimental config option for MSC3890 --- synapse/config/experimental.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/synapse/config/experimental.py b/synapse/config/experimental.py index 0f3870bfe18e..f8e72c9df5e4 100644 --- a/synapse/config/experimental.py +++ b/synapse/config/experimental.py @@ -17,6 +17,7 @@ import attr from synapse.api.room_versions import KNOWN_ROOM_VERSIONS, RoomVersions +from synapse.config import ConfigError from synapse.config._base import Config from synapse.types import JsonDict @@ -93,6 +94,9 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None: # MSC2815 (allow room moderators to view redacted event content) self.msc2815_enabled: bool = experimental.get("msc2815_enabled", False) + # MSC3391: Removing account data. + self.msc3391_enabled = experimental.get("msc3391_enabled", False) + # MSC3773: Thread notifications self.msc3773_enabled: bool = experimental.get("msc3773_enabled", False) @@ -127,6 +131,17 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None: "msc3886_endpoint", None ) + # MSC3890: Remotely silence local notifications + # Note: This option requires "experimental_features.msc3391_enabled" to be + # set to "true", in order to communicate account data deletions to clients. + self.msc3890_enabled: bool = experimental.get("msc3890_enabled", False) + if self.msc3890_enabled and not self.msc3391_enabled: + raise ConfigError( + "Option 'experimental_features.msc3391' must be set to 'true' to " + "enable 'experimental_features.msc3890'. MSC3391 functionality is " + "required to communicate account data deletions to clients." + ) + # MSC3912: Relation-based redactions. self.msc3912_enabled: bool = experimental.get("msc3912_enabled", False) @@ -136,6 +151,3 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None: # Enable room version (and thus applicable push rules from MSC3931/3932) version_id = RoomVersions.MSC1767v10.identifier KNOWN_ROOM_VERSIONS[version_id] = RoomVersions.MSC1767v10 - - # MSC3391: Removing account data. - self.msc3391_enabled = experimental.get("msc3391_enabled", False) From 48193b83f8b2933b54ef7136cb8da44faf260bcf Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Tue, 3 Jan 2023 15:09:57 +0000 Subject: [PATCH 2/6] Enable support for msc3890 in synapse's complement runs --- docker/complement/conf/workers-shared-extra.yaml.j2 | 2 ++ scripts-dev/complement.sh | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docker/complement/conf/workers-shared-extra.yaml.j2 b/docker/complement/conf/workers-shared-extra.yaml.j2 index cb839fed078d..1170694df501 100644 --- a/docker/complement/conf/workers-shared-extra.yaml.j2 +++ b/docker/complement/conf/workers-shared-extra.yaml.j2 @@ -102,6 +102,8 @@ experimental_features: {% endif %} # Filtering /messages by relation type. msc3874_enabled: true + # Enable deleting device-specific notification settings stored in account data + msc3890_enabled: true # Enable removing account data support msc3391_enabled: true diff --git a/scripts-dev/complement.sh b/scripts-dev/complement.sh index 51d1bac6183c..7c48d8bccb0f 100755 --- a/scripts-dev/complement.sh +++ b/scripts-dev/complement.sh @@ -190,7 +190,7 @@ fi extra_test_args=() -test_tags="synapse_blacklist,msc3787,msc3874,msc3391" +test_tags="synapse_blacklist,msc3787,msc3874,msc3890,msc3391" # All environment variables starting with PASS_ will be shared. # (The prefix is stripped off before reaching the container.) From 7009ac28ea6be3ba886c09f469fdc3f8c2cfaef6 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Tue, 3 Jan 2023 15:10:33 +0000 Subject: [PATCH 3/6] Remove device-specific notification settings stored in account data when device is deleted --- synapse/handlers/device.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/synapse/handlers/device.py b/synapse/handlers/device.py index d4750a32e644..15346cecb76c 100644 --- a/synapse/handlers/device.py +++ b/synapse/handlers/device.py @@ -499,7 +499,7 @@ async def delete_devices(self, user_id: str, device_ids: List[str]) -> None: else: raise - # Delete access tokens and e2e keys for each device. Not optimised as it is not + # Delete data specific to this device. Not optimised as it is not # considered as part of a critical path. for device_id in device_ids: await self._auth_handler.delete_access_tokens_for_user( @@ -509,6 +509,14 @@ async def delete_devices(self, user_id: str, device_ids: List[str]) -> None: user_id=user_id, device_id=device_id ) + if self.hs.config.experimental.msc3890_enabled: + # Remove any local notification settings for this device in accordance + # with MSC3890. + await self.store.remove_account_data_for_user( + user_id, + f"org.matrix.msc3890.local_notification_settings.{device_id}", + ) + await self.notify_device_update(user_id, device_ids) async def update_device(self, user_id: str, device_id: str, content: dict) -> None: From 300ea76d64723a562d92da758dbb3d830c99de47 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Tue, 3 Jan 2023 19:03:53 +0000 Subject: [PATCH 4/6] changelog --- changelog.d/14775.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/14775.feature diff --git a/changelog.d/14775.feature b/changelog.d/14775.feature new file mode 100644 index 000000000000..7b7ee42cacba --- /dev/null +++ b/changelog.d/14775.feature @@ -0,0 +1 @@ +Implement support for MSC3890: Remotely silence local notifications. \ No newline at end of file From 284017fbdb61f6af8a9247cf219163cf3e32310d Mon Sep 17 00:00:00 2001 From: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> Date: Thu, 12 Jan 2023 17:12:51 +0000 Subject: [PATCH 5/6] Update synapse/handlers/device.py Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com> --- synapse/handlers/device.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/handlers/device.py b/synapse/handlers/device.py index 15346cecb76c..e136b92d74f6 100644 --- a/synapse/handlers/device.py +++ b/synapse/handlers/device.py @@ -499,7 +499,7 @@ async def delete_devices(self, user_id: str, device_ids: List[str]) -> None: else: raise - # Delete data specific to this device. Not optimised as it is not + # Delete data specific to each device. Not optimised as it is not # considered as part of a critical path. for device_id in device_ids: await self._auth_handler.delete_access_tokens_for_user( From 70d7cbf4f2796c84530c422a18d91e335fa8e766 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Fri, 13 Jan 2023 18:53:18 +0000 Subject: [PATCH 6/6] Inform workers and other processes of account data change --- synapse/handlers/device.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/synapse/handlers/device.py b/synapse/handlers/device.py index a4d5a7129a5b..0640ea79a03d 100644 --- a/synapse/handlers/device.py +++ b/synapse/handlers/device.py @@ -346,6 +346,7 @@ def __init__(self, hs: "HomeServer"): super().__init__(hs) self.federation_sender = hs.get_federation_sender() + self._account_data_handler = hs.get_account_data_handler() self._storage_controllers = hs.get_storage_controllers() self.device_list_updater = DeviceListUpdater(hs, self) @@ -515,7 +516,7 @@ async def delete_devices(self, user_id: str, device_ids: List[str]) -> None: if self.hs.config.experimental.msc3890_enabled: # Remove any local notification settings for this device in accordance # with MSC3890. - await self.store.remove_account_data_for_user( + await self._account_data_handler.remove_account_data_for_user( user_id, f"org.matrix.msc3890.local_notification_settings.{device_id}", )