From e5f33c58cc5e928ab2e63f4e731534019780f0ff Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Mon, 1 May 2023 18:36:59 -0700 Subject: [PATCH] fall back to default config setting if not enabled in table --- synapse/config/experimental.py | 15 +++++++++++++++ synapse/handlers/presence.py | 4 ++++ synapse/push/bulk_push_rule_evaluator.py | 3 +++ synapse/rest/client/keys.py | 8 +++++++- synapse/rest/client/pusher.py | 23 ++++++++++++++--------- synapse/rest/client/sync.py | 9 +++++++-- 6 files changed, 50 insertions(+), 12 deletions(-) diff --git a/synapse/config/experimental.py b/synapse/config/experimental.py index 573763f270..6599679731 100644 --- a/synapse/config/experimental.py +++ b/synapse/config/experimental.py @@ -43,6 +43,9 @@ class ExperimentalConfig(Config): def read_config(self, config: JsonDict, **kwargs: Any) -> None: experimental = config.get("experimental_features") or {} + # MSC3026 (busy presence state) + self.msc3026_enabled: bool = experimental.get("msc3026_enabled", False) + # MSC2716 (importing historical messages) self.msc2716_enabled: bool = experimental.get("msc2716_enabled", False) @@ -96,6 +99,12 @@ class ExperimentalConfig(Config): # MSC3720 (Account status endpoint) self.msc3720_enabled: bool = experimental.get("msc3720_enabled", False) + # MSC2654: Unread counts + # + # Note that enabling this will result in an incorrect unread count for + # previously calculated push actions. + self.msc2654_enabled: bool = experimental.get("msc2654_enabled", False) + # MSC2815 (allow room moderators to view redacted event content) self.msc2815_enabled: bool = experimental.get("msc2815_enabled", False) @@ -118,6 +127,9 @@ class ExperimentalConfig(Config): raw_msc3866_config = experimental.get("msc3866", {}) self.msc3866 = MSC3866Config(**raw_msc3866_config) + # MSC3881: Remotely toggle push notifications for another client + self.msc3881_enabled: bool = experimental.get("msc3881_enabled", False) + # MSC3882: Allow an existing session to sign in a new session self.msc3882_enabled: bool = experimental.get("msc3882_enabled", False) self.msc3882_ui_auth: bool = experimental.get("msc3882_ui_auth", True) @@ -174,6 +186,9 @@ class ExperimentalConfig(Config): "msc3958_supress_edit_notifs", False ) + # MSC3967: Do not require UIA when first uploading cross signing keys + self.msc3967_enabled = experimental.get("msc3967_enabled", False) + # MSC2659: Application service ping endpoint self.msc2659_enabled = experimental.get("msc2659_enabled", False) diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py index e841c1b1b8..08649eaf7b 100644 --- a/synapse/handlers/presence.py +++ b/synapse/handlers/presence.py @@ -608,6 +608,8 @@ class WorkerPresenceHandler(BasePresenceHandler): busy_presence_enabled = await self.hs.get_datastores().main.get_feature_enabled( target_user.to_string(), "msc3026" ) + if not busy_presence_enabled: + busy_presence_enabled = self.hs.config.experimental.msc3026_enabled if presence not in valid_presence or ( presence == PresenceState.BUSY and not busy_presence_enabled @@ -1241,6 +1243,8 @@ class PresenceHandler(BasePresenceHandler): busy_presence_enabled = await self.hs.get_datastores().main.get_feature_enabled( target_user.to_string(), "msc3026" ) + if not busy_presence_enabled: + busy_presence_enabled = self.hs.config.experimental.msc3026_enabled if presence not in valid_presence or ( presence == PresenceState.BUSY and not busy_presence_enabled diff --git a/synapse/push/bulk_push_rule_evaluator.py b/synapse/push/bulk_push_rule_evaluator.py index a2d00645f0..ec78e77c11 100644 --- a/synapse/push/bulk_push_rule_evaluator.py +++ b/synapse/push/bulk_push_rule_evaluator.py @@ -438,6 +438,9 @@ class BulkPushRuleEvaluator: # check whether unread counts are enabled for this user unread_enabled = await self.store.get_feature_enabled(uid, "msc2654") + if not unread_enabled: + unread_enabled = self.hs.config.experimental.msc2654_enabled + if unread_enabled: count_as_unread = _should_count_as_unread(event, context) else: diff --git a/synapse/rest/client/keys.py b/synapse/rest/client/keys.py index 2f3058d3fb..08bd38d7aa 100644 --- a/synapse/rest/client/keys.py +++ b/synapse/rest/client/keys.py @@ -375,7 +375,13 @@ class SigningKeyUploadServlet(RestServlet): user_id = requester.user.to_string() body = parse_json_object_from_request(request) - if await self.hs.get_datastores().main.get_feature_enabled(user_id, "msc3967"): + msc3967_enabled = await self.hs.get_datastores().main.get_feature_enabled( + user_id, "msc3967" + ) + if not msc3967_enabled: + msc3967_enabled = self.hs.config.experimental.msc2654_enabled + + if msc3967_enabled: if await self.e2e_keys_handler.is_cross_signing_set_up_for_user(user_id): # If we already have a master key then cross signing is set up and we require UIA to reset await self.auth_handler.validate_user_via_ui_auth( diff --git a/synapse/rest/client/pusher.py b/synapse/rest/client/pusher.py index 0cc63dc5de..d6c0f1bd16 100644 --- a/synapse/rest/client/pusher.py +++ b/synapse/rest/client/pusher.py @@ -53,10 +53,14 @@ class PushersRestServlet(RestServlet): pusher_dicts = [p.as_dict() for p in pushers] + msc3881_enabled = await self.hs.get_datastores().main.get_feature_enabled( + user.to_string(), "msc3881" + ) + if not msc3881_enabled: + msc3881_enabled = self.hs.config.experimental.msc3881_enabled + for pusher in pusher_dicts: - if await self.hs.get_datastores().main.get_feature_enabled( - user.to_string(), "msc3881" - ): + if msc3881_enabled: pusher["org.matrix.msc3881.enabled"] = pusher["enabled"] pusher["org.matrix.msc3881.device_id"] = pusher["device_id"] del pusher["enabled"] @@ -113,12 +117,13 @@ class PushersSetRestServlet(RestServlet): append = content["append"] enabled = True - if ( - await self.hs.get_datastores().main.get_feature_enabled( - user.to_string(), "msc3881" - ) - and "org.matrix.msc3881.enabled" in content - ): + msc3881_enabled = await self.hs.get_datastores().main.get_feature_enabled( + user.to_string(), "msc3881" + ) + if not msc3881_enabled: + msc3881_enabled = self.hs.config.experimental.msc3881_enabled + + if msc3881_enabled and "org.matrix.msc3881.enabled" in content: enabled = content["org.matrix.msc3881.enabled"] if not append: diff --git a/synapse/rest/client/sync.py b/synapse/rest/client/sync.py index 7ae96493cb..0a5e08875f 100644 --- a/synapse/rest/client/sync.py +++ b/synapse/rest/client/sync.py @@ -552,9 +552,14 @@ class SyncRestServlet(RestServlet): "org.matrix.msc3773.unread_thread_notifications" ] = room.unread_thread_notifications result["summary"] = room.summary - if await self.store.get_feature_enabled( + + msc2654_enabled = await self.hs.get_datastores().main.get_feature_enabled( requester.user.to_string(), "msc2654" - ): + ) + if not msc2654_enabled: + msc2654_enabled = self.hs.config.experimental.msc2654_enabled + + if msc2654_enabled: result["org.matrix.msc2654.unread_count"] = room.unread_count return result