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

Commit

Permalink
fall back to default config setting if not enabled in table
Browse files Browse the repository at this point in the history
  • Loading branch information
H-Shay committed May 2, 2023
1 parent efeb79c commit a49b24b
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 12 deletions.
15 changes: 15 additions & 0 deletions synapse/config/experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -96,6 +99,12 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
# 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)

Expand All @@ -118,6 +127,9 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
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)
Expand Down Expand Up @@ -174,6 +186,9 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
"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)

Expand Down
4 changes: 4 additions & 0 deletions synapse/handlers/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,8 @@ async def set_state(
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
Expand Down Expand Up @@ -1241,6 +1243,8 @@ async def set_state(
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
Expand Down
3 changes: 3 additions & 0 deletions synapse/push/bulk_push_rule_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ async def _action_for_event_by_user(

# 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:
Expand Down
8 changes: 7 additions & 1 deletion synapse/rest/client/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,13 @@ async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
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(
Expand Down
23 changes: 14 additions & 9 deletions synapse/rest/client/pusher.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@ async def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]:

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"]
Expand Down Expand Up @@ -113,12 +117,13 @@ async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
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:
Expand Down
9 changes: 7 additions & 2 deletions synapse/rest/client/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,14 @@ async def encode_room(
"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
Expand Down

0 comments on commit a49b24b

Please sign in to comment.