mirror of
https://github.com/element-hq/synapse.git
synced 2024-12-14 11:57:44 +00:00
Stabilize support for MSC3966: event_property_contains push condition. (#15187)
This removes the configuration flag & updates the identifiers to use the stable version.
This commit is contained in:
parent
2af1a982c1
commit
820f02b70b
9 changed files with 13 additions and 55 deletions
1
changelog.d/15187.feature
Normal file
1
changelog.d/15187.feature
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Stabilise support for [MSC3966](https://github.com/matrix-org/matrix-spec-proposals/pull/3966): `event_property_contains` push condition.
|
|
@ -52,7 +52,6 @@ fn bench_match_exact(b: &mut Bencher) {
|
||||||
true,
|
true,
|
||||||
vec![],
|
vec![],
|
||||||
false,
|
false,
|
||||||
false,
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -98,7 +97,6 @@ fn bench_match_word(b: &mut Bencher) {
|
||||||
true,
|
true,
|
||||||
vec![],
|
vec![],
|
||||||
false,
|
false,
|
||||||
false,
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -144,7 +142,6 @@ fn bench_match_word_miss(b: &mut Bencher) {
|
||||||
true,
|
true,
|
||||||
vec![],
|
vec![],
|
||||||
false,
|
false,
|
||||||
false,
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -190,7 +187,6 @@ fn bench_eval_message(b: &mut Bencher) {
|
||||||
true,
|
true,
|
||||||
vec![],
|
vec![],
|
||||||
false,
|
false,
|
||||||
false,
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -96,9 +96,6 @@ pub struct PushRuleEvaluator {
|
||||||
/// If MSC3931 (room version feature flags) is enabled. Usually controlled by the same
|
/// If MSC3931 (room version feature flags) is enabled. Usually controlled by the same
|
||||||
/// flag as MSC1767 (extensible events core).
|
/// flag as MSC1767 (extensible events core).
|
||||||
msc3931_enabled: bool,
|
msc3931_enabled: bool,
|
||||||
|
|
||||||
/// If MSC3966 (exact_event_property_contains push rule condition) is enabled.
|
|
||||||
msc3966_exact_event_property_contains: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pymethods]
|
#[pymethods]
|
||||||
|
@ -116,7 +113,6 @@ impl PushRuleEvaluator {
|
||||||
related_event_match_enabled: bool,
|
related_event_match_enabled: bool,
|
||||||
room_version_feature_flags: Vec<String>,
|
room_version_feature_flags: Vec<String>,
|
||||||
msc3931_enabled: bool,
|
msc3931_enabled: bool,
|
||||||
msc3966_exact_event_property_contains: bool,
|
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let body = match flattened_keys.get("content.body") {
|
let body = match flattened_keys.get("content.body") {
|
||||||
Some(JsonValue::Value(SimpleJsonValue::Str(s))) => s.clone(),
|
Some(JsonValue::Value(SimpleJsonValue::Str(s))) => s.clone(),
|
||||||
|
@ -134,7 +130,6 @@ impl PushRuleEvaluator {
|
||||||
related_event_match_enabled,
|
related_event_match_enabled,
|
||||||
room_version_feature_flags,
|
room_version_feature_flags,
|
||||||
msc3931_enabled,
|
msc3931_enabled,
|
||||||
msc3966_exact_event_property_contains,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,8 +296,8 @@ impl PushRuleEvaluator {
|
||||||
Some(Cow::Borrowed(pattern)),
|
Some(Cow::Borrowed(pattern)),
|
||||||
)?
|
)?
|
||||||
}
|
}
|
||||||
KnownCondition::ExactEventPropertyContains(event_property_is) => self
|
KnownCondition::EventPropertyContains(event_property_is) => self
|
||||||
.match_exact_event_property_contains(
|
.match_event_property_contains(
|
||||||
event_property_is.key.clone(),
|
event_property_is.key.clone(),
|
||||||
event_property_is.value.clone(),
|
event_property_is.value.clone(),
|
||||||
)?,
|
)?,
|
||||||
|
@ -321,7 +316,7 @@ impl PushRuleEvaluator {
|
||||||
EventMatchPatternType::UserLocalpart => get_localpart_from_id(user_id)?,
|
EventMatchPatternType::UserLocalpart => get_localpart_from_id(user_id)?,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.match_exact_event_property_contains(
|
self.match_event_property_contains(
|
||||||
exact_event_match.key.clone(),
|
exact_event_match.key.clone(),
|
||||||
Cow::Borrowed(&SimpleJsonValue::Str(pattern.to_string())),
|
Cow::Borrowed(&SimpleJsonValue::Str(pattern.to_string())),
|
||||||
)?
|
)?
|
||||||
|
@ -454,17 +449,12 @@ impl PushRuleEvaluator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Evaluates a `exact_event_property_contains` condition. (MSC3966)
|
/// Evaluates a `event_property_contains` condition.
|
||||||
fn match_exact_event_property_contains(
|
fn match_event_property_contains(
|
||||||
&self,
|
&self,
|
||||||
key: Cow<str>,
|
key: Cow<str>,
|
||||||
value: Cow<SimpleJsonValue>,
|
value: Cow<SimpleJsonValue>,
|
||||||
) -> Result<bool, Error> {
|
) -> Result<bool, Error> {
|
||||||
// First check if the feature is enabled.
|
|
||||||
if !self.msc3966_exact_event_property_contains {
|
|
||||||
return Ok(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
let haystack = if let Some(JsonValue::Array(haystack)) = self.flattened_keys.get(&*key) {
|
let haystack = if let Some(JsonValue::Array(haystack)) = self.flattened_keys.get(&*key) {
|
||||||
haystack
|
haystack
|
||||||
} else {
|
} else {
|
||||||
|
@ -515,7 +505,6 @@ fn push_rule_evaluator() {
|
||||||
true,
|
true,
|
||||||
vec![],
|
vec![],
|
||||||
true,
|
true,
|
||||||
true,
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -545,7 +534,6 @@ fn test_requires_room_version_supports_condition() {
|
||||||
false,
|
false,
|
||||||
flags,
|
flags,
|
||||||
true,
|
true,
|
||||||
true,
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -337,13 +337,9 @@ pub enum KnownCondition {
|
||||||
// Identical to related_event_match but gives predefined patterns. Cannot be added by users.
|
// Identical to related_event_match but gives predefined patterns. Cannot be added by users.
|
||||||
#[serde(skip_deserializing, rename = "im.nheko.msc3664.related_event_match")]
|
#[serde(skip_deserializing, rename = "im.nheko.msc3664.related_event_match")]
|
||||||
RelatedEventMatchType(RelatedEventMatchTypeCondition),
|
RelatedEventMatchType(RelatedEventMatchTypeCondition),
|
||||||
#[serde(rename = "org.matrix.msc3966.exact_event_property_contains")]
|
EventPropertyContains(EventPropertyIsCondition),
|
||||||
ExactEventPropertyContains(EventPropertyIsCondition),
|
|
||||||
// Identical to exact_event_property_contains but gives predefined patterns. Cannot be added by users.
|
// Identical to exact_event_property_contains but gives predefined patterns. Cannot be added by users.
|
||||||
#[serde(
|
#[serde(skip_deserializing, rename = "event_property_contains")]
|
||||||
skip_deserializing,
|
|
||||||
rename = "org.matrix.msc3966.exact_event_property_contains"
|
|
||||||
)]
|
|
||||||
ExactEventPropertyContainsType(EventPropertyIsTypeCondition),
|
ExactEventPropertyContainsType(EventPropertyIsTypeCondition),
|
||||||
ContainsDisplayName,
|
ContainsDisplayName,
|
||||||
RoomMemberCount {
|
RoomMemberCount {
|
||||||
|
|
|
@ -65,7 +65,6 @@ class PushRuleEvaluator:
|
||||||
related_event_match_enabled: bool,
|
related_event_match_enabled: bool,
|
||||||
room_version_feature_flags: Tuple[str, ...],
|
room_version_feature_flags: Tuple[str, ...],
|
||||||
msc3931_enabled: bool,
|
msc3931_enabled: bool,
|
||||||
msc3966_exact_event_property_contains: bool,
|
|
||||||
): ...
|
): ...
|
||||||
def run(
|
def run(
|
||||||
self,
|
self,
|
||||||
|
|
|
@ -171,15 +171,9 @@ class ExperimentalConfig(Config):
|
||||||
"msc3873_escape_event_match_key", False
|
"msc3873_escape_event_match_key", False
|
||||||
)
|
)
|
||||||
|
|
||||||
# MSC3966: exact_event_property_contains push rule condition.
|
|
||||||
self.msc3966_exact_event_property_contains = experimental.get(
|
|
||||||
"msc3966_exact_event_property_contains", False
|
|
||||||
)
|
|
||||||
|
|
||||||
# MSC3952: Intentional mentions, this depends on MSC3966.
|
# MSC3952: Intentional mentions, this depends on MSC3966.
|
||||||
self.msc3952_intentional_mentions = (
|
self.msc3952_intentional_mentions = experimental.get(
|
||||||
experimental.get("msc3952_intentional_mentions", False)
|
"msc3952_intentional_mentions", False
|
||||||
and self.msc3966_exact_event_property_contains
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# MSC3959: Do not generate notifications for edits.
|
# MSC3959: Do not generate notifications for edits.
|
||||||
|
|
|
@ -413,7 +413,6 @@ class BulkPushRuleEvaluator:
|
||||||
self._related_event_match_enabled,
|
self._related_event_match_enabled,
|
||||||
event.room_version.msc3931_push_features,
|
event.room_version.msc3931_push_features,
|
||||||
self.hs.config.experimental.msc1767_enabled, # MSC3931 flag
|
self.hs.config.experimental.msc1767_enabled, # MSC3931 flag
|
||||||
self.hs.config.experimental.msc3966_exact_event_property_contains,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
users = rules_by_user.keys()
|
users = rules_by_user.keys()
|
||||||
|
|
|
@ -228,14 +228,7 @@ class TestBulkPushRuleEvaluator(HomeserverTestCase):
|
||||||
)
|
)
|
||||||
return len(result) > 0
|
return len(result) > 0
|
||||||
|
|
||||||
@override_config(
|
@override_config({"experimental_features": {"msc3952_intentional_mentions": True}})
|
||||||
{
|
|
||||||
"experimental_features": {
|
|
||||||
"msc3952_intentional_mentions": True,
|
|
||||||
"msc3966_exact_event_property_contains": True,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
def test_user_mentions(self) -> None:
|
def test_user_mentions(self) -> None:
|
||||||
"""Test the behavior of an event which includes invalid user mentions."""
|
"""Test the behavior of an event which includes invalid user mentions."""
|
||||||
bulk_evaluator = BulkPushRuleEvaluator(self.hs)
|
bulk_evaluator = BulkPushRuleEvaluator(self.hs)
|
||||||
|
@ -331,14 +324,7 @@ class TestBulkPushRuleEvaluator(HomeserverTestCase):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@override_config(
|
@override_config({"experimental_features": {"msc3952_intentional_mentions": True}})
|
||||||
{
|
|
||||||
"experimental_features": {
|
|
||||||
"msc3952_intentional_mentions": True,
|
|
||||||
"msc3966_exact_event_property_contains": True,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
def test_room_mentions(self) -> None:
|
def test_room_mentions(self) -> None:
|
||||||
"""Test the behavior of an event which includes invalid room mentions."""
|
"""Test the behavior of an event which includes invalid room mentions."""
|
||||||
bulk_evaluator = BulkPushRuleEvaluator(self.hs)
|
bulk_evaluator = BulkPushRuleEvaluator(self.hs)
|
||||||
|
|
|
@ -173,7 +173,6 @@ class PushRuleEvaluatorTestCase(unittest.TestCase):
|
||||||
related_event_match_enabled=True,
|
related_event_match_enabled=True,
|
||||||
room_version_feature_flags=event.room_version.msc3931_push_features,
|
room_version_feature_flags=event.room_version.msc3931_push_features,
|
||||||
msc3931_enabled=True,
|
msc3931_enabled=True,
|
||||||
msc3966_exact_event_property_contains=True,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_display_name(self) -> None:
|
def test_display_name(self) -> None:
|
||||||
|
@ -526,7 +525,7 @@ class PushRuleEvaluatorTestCase(unittest.TestCase):
|
||||||
"""Check that exact_event_property_contains conditions work as expected."""
|
"""Check that exact_event_property_contains conditions work as expected."""
|
||||||
|
|
||||||
condition = {
|
condition = {
|
||||||
"kind": "org.matrix.msc3966.exact_event_property_contains",
|
"kind": "event_property_contains",
|
||||||
"key": "content.value",
|
"key": "content.value",
|
||||||
"value": "foobaz",
|
"value": "foobaz",
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue