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

Commit

Permalink
Create experimental flag for future work, and use it to gate MSC3931
Browse files Browse the repository at this point in the history
  • Loading branch information
turt2live committed Nov 22, 2022
1 parent 266f5d6 commit 4eb3ba8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
16 changes: 14 additions & 2 deletions rust/src/push/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ pub struct PushRuleEvaluator {

/// If MSC3931 is applicable, the feature flags for the room version.
room_version_feature_flags: Vec<String>,

/// If MSC3931 (room version feature flags) is enabled. Usually controlled by the same
/// flag as MSC1767 (extensible events core).
msc3931_enabled: bool,
}

#[pymethods]
Expand All @@ -78,6 +82,7 @@ impl PushRuleEvaluator {
related_events_flattened: BTreeMap<String, BTreeMap<String, String>>,
related_event_match_enabled: bool,
room_version_feature_flags: Vec<String>,
msc3931_enabled: bool,
) -> Result<Self, Error> {
let body = flattened_keys
.get("content.body")
Expand All @@ -93,6 +98,7 @@ impl PushRuleEvaluator {
related_events_flattened,
related_event_match_enabled,
room_version_feature_flags,
msc3931_enabled,
})
}

Expand Down Expand Up @@ -214,8 +220,13 @@ impl PushRuleEvaluator {
}
}
KnownCondition::RoomVersionSupports { feature } => {
let flag = feature.to_string();
KNOWN_RVER_FLAGS.contains(&flag) && self.room_version_feature_flags.contains(&flag)
if !self.msc3931_enabled {
false
} else {
let flag = feature.to_string();
KNOWN_RVER_FLAGS.contains(&flag)
&& self.room_version_feature_flags.contains(&flag)
}
}
};

Expand Down Expand Up @@ -376,6 +387,7 @@ fn push_rule_evaluator() {
BTreeMap::new(),
true,
vec![],
true,
)
.unwrap();

Expand Down
1 change: 1 addition & 0 deletions stubs/synapse/synapse_rust/push.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class PushRuleEvaluator:
related_events_flattened: Mapping[str, Mapping[str, str]],
related_event_match_enabled: bool,
room_version_feature_flags: list[str],
msc3931_enabled: bool,
): ...
def run(
self,
Expand Down
3 changes: 3 additions & 0 deletions synapse/config/experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,6 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:

# MSC3912: Relation-based redactions.
self.msc3912_enabled: bool = experimental.get("msc3912_enabled", False)

# MSC1767 and friends: Extensible Events
self.msc1767_enabled: bool = experimental.get("msc1767_enabled", False)
1 change: 1 addition & 0 deletions synapse/push/bulk_push_rule_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ async def _action_for_event_by_user(
related_events,
self._related_event_match_enabled,
room_version_features,
self.hs.config.experimental.msc1767_enabled, # MSC3931 flag
)

users = rules_by_user.keys()
Expand Down
1 change: 1 addition & 0 deletions tests/push/test_push_rule_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def _get_evaluator(
{} if related_events is None else related_events,
True,
event.room_version.msc3931_push_features,
True,
)

def test_display_name(self) -> None:
Expand Down

0 comments on commit 4eb3ba8

Please sign in to comment.