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

Commit fd9cadc

Browse files
authored
Stabilize support for MSC3758: event_property_is push condition (#15185)
This removes the configuration flag & updates the identifiers to use the stable version.
1 parent 95876cf commit fd9cadc

File tree

10 files changed

+39
-81
lines changed

10 files changed

+39
-81
lines changed

changelog.d/15185.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Stabilise support for [MSC3758](https://github.com/matrix-org/matrix-spec-proposals/pull/3758): `event_property_is` push condition.

rust/benches/evaluator.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ fn bench_match_exact(b: &mut Bencher) {
5353
vec![],
5454
false,
5555
false,
56-
false,
5756
)
5857
.unwrap();
5958

@@ -100,7 +99,6 @@ fn bench_match_word(b: &mut Bencher) {
10099
vec![],
101100
false,
102101
false,
103-
false,
104102
)
105103
.unwrap();
106104

@@ -147,7 +145,6 @@ fn bench_match_word_miss(b: &mut Bencher) {
147145
vec![],
148146
false,
149147
false,
150-
false,
151148
)
152149
.unwrap();
153150

@@ -194,7 +191,6 @@ fn bench_eval_message(b: &mut Bencher) {
194191
vec![],
195192
false,
196193
false,
197-
false,
198194
)
199195
.unwrap();
200196

rust/src/push/base_rules.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ use super::KnownCondition;
2424
use crate::push::RelatedEventMatchTypeCondition;
2525
use crate::push::SetTweak;
2626
use crate::push::TweakValue;
27-
use crate::push::{Action, ExactEventMatchCondition, SimpleJsonValue};
27+
use crate::push::{Action, EventPropertyIsCondition, SimpleJsonValue};
2828
use crate::push::{Condition, EventMatchTypeCondition};
2929
use crate::push::{EventMatchCondition, EventMatchPatternType};
30-
use crate::push::{ExactEventMatchTypeCondition, PushRule};
30+
use crate::push::{EventPropertyIsTypeCondition, PushRule};
3131

3232
const HIGHLIGHT_ACTION: Action = Action::SetTweak(SetTweak {
3333
set_tweak: Cow::Borrowed("highlight"),
@@ -145,7 +145,7 @@ pub const BASE_APPEND_OVERRIDE_RULES: &[PushRule] = &[
145145
rule_id: Cow::Borrowed(".org.matrix.msc3952.is_user_mention"),
146146
priority_class: 5,
147147
conditions: Cow::Borrowed(&[Condition::Known(
148-
KnownCondition::ExactEventPropertyContainsType(ExactEventMatchTypeCondition {
148+
KnownCondition::ExactEventPropertyContainsType(EventPropertyIsTypeCondition {
149149
key: Cow::Borrowed("content.org.matrix.msc3952.mentions.user_ids"),
150150
value_type: Cow::Borrowed(&EventMatchPatternType::UserId),
151151
}),
@@ -166,7 +166,7 @@ pub const BASE_APPEND_OVERRIDE_RULES: &[PushRule] = &[
166166
rule_id: Cow::Borrowed(".org.matrix.msc3952.is_room_mention"),
167167
priority_class: 5,
168168
conditions: Cow::Borrowed(&[
169-
Condition::Known(KnownCondition::ExactEventMatch(ExactEventMatchCondition {
169+
Condition::Known(KnownCondition::EventPropertyIs(EventPropertyIsCondition {
170170
key: Cow::Borrowed("content.org.matrix.msc3952.mentions.room"),
171171
value: Cow::Borrowed(&SimpleJsonValue::Bool(true)),
172172
})),

rust/src/push/evaluator.rs

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use regex::Regex;
2323

2424
use super::{
2525
utils::{get_glob_matcher, get_localpart_from_id, GlobMatchType},
26-
Action, Condition, ExactEventMatchCondition, FilteredPushRules, KnownCondition,
26+
Action, Condition, EventPropertyIsCondition, FilteredPushRules, KnownCondition,
2727
SimpleJsonValue,
2828
};
2929
use crate::push::{EventMatchPatternType, JsonValue};
@@ -97,9 +97,6 @@ pub struct PushRuleEvaluator {
9797
/// flag as MSC1767 (extensible events core).
9898
msc3931_enabled: bool,
9999

100-
/// If MSC3758 (exact_event_match push rule condition) is enabled.
101-
msc3758_exact_event_match: bool,
102-
103100
/// If MSC3966 (exact_event_property_contains push rule condition) is enabled.
104101
msc3966_exact_event_property_contains: bool,
105102
}
@@ -119,7 +116,6 @@ impl PushRuleEvaluator {
119116
related_event_match_enabled: bool,
120117
room_version_feature_flags: Vec<String>,
121118
msc3931_enabled: bool,
122-
msc3758_exact_event_match: bool,
123119
msc3966_exact_event_property_contains: bool,
124120
) -> Result<Self, Error> {
125121
let body = match flattened_keys.get("content.body") {
@@ -138,7 +134,6 @@ impl PushRuleEvaluator {
138134
related_event_match_enabled,
139135
room_version_feature_flags,
140136
msc3931_enabled,
141-
msc3758_exact_event_match,
142137
msc3966_exact_event_property_contains,
143138
})
144139
}
@@ -275,8 +270,8 @@ impl PushRuleEvaluator {
275270

276271
self.match_event_match(&self.flattened_keys, &event_match.key, pattern)?
277272
}
278-
KnownCondition::ExactEventMatch(exact_event_match) => {
279-
self.match_exact_event_match(exact_event_match)?
273+
KnownCondition::EventPropertyIs(event_property_is) => {
274+
self.match_event_property_is(event_property_is)?
280275
}
281276
KnownCondition::RelatedEventMatch(event_match) => self.match_related_event_match(
282277
&event_match.rel_type.clone(),
@@ -306,10 +301,10 @@ impl PushRuleEvaluator {
306301
Some(Cow::Borrowed(pattern)),
307302
)?
308303
}
309-
KnownCondition::ExactEventPropertyContains(exact_event_match) => self
304+
KnownCondition::ExactEventPropertyContains(event_property_is) => self
310305
.match_exact_event_property_contains(
311-
exact_event_match.key.clone(),
312-
exact_event_match.value.clone(),
306+
event_property_is.key.clone(),
307+
event_property_is.value.clone(),
313308
)?,
314309
KnownCondition::ExactEventPropertyContainsType(exact_event_match) => {
315310
// The `pattern_type` can either be "user_id" or "user_localpart",
@@ -405,20 +400,15 @@ impl PushRuleEvaluator {
405400
compiled_pattern.is_match(haystack)
406401
}
407402

408-
/// Evaluates a `exact_event_match` condition. (MSC3758)
409-
fn match_exact_event_match(
403+
/// Evaluates a `event_property_is` condition.
404+
fn match_event_property_is(
410405
&self,
411-
exact_event_match: &ExactEventMatchCondition,
406+
event_property_is: &EventPropertyIsCondition,
412407
) -> Result<bool, Error> {
413-
// First check if the feature is enabled.
414-
if !self.msc3758_exact_event_match {
415-
return Ok(false);
416-
}
417-
418-
let value = &exact_event_match.value;
408+
let value = &event_property_is.value;
419409

420410
let haystack = if let Some(JsonValue::Value(haystack)) =
421-
self.flattened_keys.get(&*exact_event_match.key)
411+
self.flattened_keys.get(&*event_property_is.key)
422412
{
423413
haystack
424414
} else {
@@ -464,7 +454,7 @@ impl PushRuleEvaluator {
464454
}
465455
}
466456

467-
/// Evaluates a `exact_event_property_contains` condition. (MSC3758)
457+
/// Evaluates a `exact_event_property_contains` condition. (MSC3966)
468458
fn match_exact_event_property_contains(
469459
&self,
470460
key: Cow<str>,
@@ -526,7 +516,6 @@ fn push_rule_evaluator() {
526516
vec![],
527517
true,
528518
true,
529-
true,
530519
)
531520
.unwrap();
532521

@@ -557,7 +546,6 @@ fn test_requires_room_version_supports_condition() {
557546
flags,
558547
true,
559548
true,
560-
true,
561549
)
562550
.unwrap();
563551

rust/src/push/mod.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -331,21 +331,20 @@ pub enum KnownCondition {
331331
// Identical to event_match but gives predefined patterns. Cannot be added by users.
332332
#[serde(skip_deserializing, rename = "event_match")]
333333
EventMatchType(EventMatchTypeCondition),
334-
#[serde(rename = "com.beeper.msc3758.exact_event_match")]
335-
ExactEventMatch(ExactEventMatchCondition),
334+
EventPropertyIs(EventPropertyIsCondition),
336335
#[serde(rename = "im.nheko.msc3664.related_event_match")]
337336
RelatedEventMatch(RelatedEventMatchCondition),
338337
// Identical to related_event_match but gives predefined patterns. Cannot be added by users.
339338
#[serde(skip_deserializing, rename = "im.nheko.msc3664.related_event_match")]
340339
RelatedEventMatchType(RelatedEventMatchTypeCondition),
341340
#[serde(rename = "org.matrix.msc3966.exact_event_property_contains")]
342-
ExactEventPropertyContains(ExactEventMatchCondition),
341+
ExactEventPropertyContains(EventPropertyIsCondition),
343342
// Identical to exact_event_property_contains but gives predefined patterns. Cannot be added by users.
344343
#[serde(
345344
skip_deserializing,
346345
rename = "org.matrix.msc3966.exact_event_property_contains"
347346
)]
348-
ExactEventPropertyContainsType(ExactEventMatchTypeCondition),
347+
ExactEventPropertyContainsType(EventPropertyIsTypeCondition),
349348
ContainsDisplayName,
350349
RoomMemberCount {
351350
#[serde(skip_serializing_if = "Option::is_none")]
@@ -395,16 +394,16 @@ pub struct EventMatchTypeCondition {
395394
pub pattern_type: Cow<'static, EventMatchPatternType>,
396395
}
397396

398-
/// The body of a [`Condition::ExactEventMatch`]
397+
/// The body of a [`Condition::EventPropertyIs`]
399398
#[derive(Serialize, Deserialize, Debug, Clone)]
400-
pub struct ExactEventMatchCondition {
399+
pub struct EventPropertyIsCondition {
401400
pub key: Cow<'static, str>,
402401
pub value: Cow<'static, SimpleJsonValue>,
403402
}
404403

405-
/// The body of a [`Condition::ExactEventMatch`] that uses user_id or user_localpart as a pattern.
404+
/// The body of a [`Condition::EventPropertyIs`] that uses user_id or user_localpart as a pattern.
406405
#[derive(Serialize, Debug, Clone)]
407-
pub struct ExactEventMatchTypeCondition {
406+
pub struct EventPropertyIsTypeCondition {
408407
pub key: Cow<'static, str>,
409408
// During serialization, the pattern_type property gets replaced with a
410409
// pattern property of the correct value in synapse.push.clientformat.format_push_rules_for_user.
@@ -711,44 +710,41 @@ fn test_deserialize_unstable_msc3931_condition() {
711710
}
712711

713712
#[test]
714-
fn test_deserialize_unstable_msc3758_condition() {
713+
fn test_deserialize_event_property_is_condition() {
715714
// A string condition should work.
716-
let json =
717-
r#"{"kind":"com.beeper.msc3758.exact_event_match","key":"content.value","value":"foo"}"#;
715+
let json = r#"{"kind":"event_property_is","key":"content.value","value":"foo"}"#;
718716

719717
let condition: Condition = serde_json::from_str(json).unwrap();
720718
assert!(matches!(
721719
condition,
722-
Condition::Known(KnownCondition::ExactEventMatch(_))
720+
Condition::Known(KnownCondition::EventPropertyIs(_))
723721
));
724722

725723
// A boolean condition should work.
726-
let json =
727-
r#"{"kind":"com.beeper.msc3758.exact_event_match","key":"content.value","value":true}"#;
724+
let json = r#"{"kind":"event_property_is","key":"content.value","value":true}"#;
728725

729726
let condition: Condition = serde_json::from_str(json).unwrap();
730727
assert!(matches!(
731728
condition,
732-
Condition::Known(KnownCondition::ExactEventMatch(_))
729+
Condition::Known(KnownCondition::EventPropertyIs(_))
733730
));
734731

735732
// An integer condition should work.
736-
let json = r#"{"kind":"com.beeper.msc3758.exact_event_match","key":"content.value","value":1}"#;
733+
let json = r#"{"kind":"event_property_is","key":"content.value","value":1}"#;
737734

738735
let condition: Condition = serde_json::from_str(json).unwrap();
739736
assert!(matches!(
740737
condition,
741-
Condition::Known(KnownCondition::ExactEventMatch(_))
738+
Condition::Known(KnownCondition::EventPropertyIs(_))
742739
));
743740

744741
// A null condition should work
745-
let json =
746-
r#"{"kind":"com.beeper.msc3758.exact_event_match","key":"content.value","value":null}"#;
742+
let json = r#"{"kind":"event_property_is","key":"content.value","value":null}"#;
747743

748744
let condition: Condition = serde_json::from_str(json).unwrap();
749745
assert!(matches!(
750746
condition,
751-
Condition::Known(KnownCondition::ExactEventMatch(_))
747+
Condition::Known(KnownCondition::EventPropertyIs(_))
752748
));
753749
}
754750

stubs/synapse/synapse_rust/push.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ class PushRuleEvaluator:
6565
related_event_match_enabled: bool,
6666
room_version_feature_flags: Tuple[str, ...],
6767
msc3931_enabled: bool,
68-
msc3758_exact_event_match: bool,
6968
msc3966_exact_event_property_contains: bool,
7069
): ...
7170
def run(

synapse/config/experimental.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,6 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
169169
# MSC3925: do not replace events with their edits
170170
self.msc3925_inhibit_edit = experimental.get("msc3925_inhibit_edit", False)
171171

172-
# MSC3758: exact_event_match push rule condition
173-
self.msc3758_exact_event_match = experimental.get(
174-
"msc3758_exact_event_match", False
175-
)
176-
177172
# MSC3873: Disambiguate event_match keys.
178173
self.msc3873_escape_event_match_key = experimental.get(
179174
"msc3873_escape_event_match_key", False
@@ -184,10 +179,9 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
184179
"msc3966_exact_event_property_contains", False
185180
)
186181

187-
# MSC3952: Intentional mentions, this depends on MSC3758 and MSC3966.
182+
# MSC3952: Intentional mentions, this depends on MSC3966.
188183
self.msc3952_intentional_mentions = (
189184
experimental.get("msc3952_intentional_mentions", False)
190-
and self.msc3758_exact_event_match
191185
and self.msc3966_exact_event_property_contains
192186
)
193187

synapse/push/bulk_push_rule_evaluator.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,6 @@ async def _action_for_event_by_user(
413413
self._related_event_match_enabled,
414414
event.room_version.msc3931_push_features,
415415
self.hs.config.experimental.msc1767_enabled, # MSC3931 flag
416-
self.hs.config.experimental.msc3758_exact_event_match,
417416
self.hs.config.experimental.msc3966_exact_event_property_contains,
418417
)
419418

tests/push/test_bulk_push_rule_evaluator.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ def _create_and_process(
231231
@override_config(
232232
{
233233
"experimental_features": {
234-
"msc3758_exact_event_match": True,
235234
"msc3952_intentional_mentions": True,
236235
"msc3966_exact_event_property_contains": True,
237236
}
@@ -335,7 +334,6 @@ def test_user_mentions(self) -> None:
335334
@override_config(
336335
{
337336
"experimental_features": {
338-
"msc3758_exact_event_match": True,
339337
"msc3952_intentional_mentions": True,
340338
"msc3966_exact_event_property_contains": True,
341339
}

tests/push/test_push_rule_evaluator.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ def _get_evaluator(
173173
related_event_match_enabled=True,
174174
room_version_feature_flags=event.room_version.msc3931_push_features,
175175
msc3931_enabled=True,
176-
msc3758_exact_event_match=True,
177176
msc3966_exact_event_property_contains=True,
178177
)
179178

@@ -404,7 +403,7 @@ def test_exact_event_match_string(self) -> None:
404403

405404
# Test against a string value.
406405
condition = {
407-
"kind": "com.beeper.msc3758.exact_event_match",
406+
"kind": "event_property_is",
408407
"key": "content.value",
409408
"value": "foobaz",
410409
}
@@ -442,11 +441,7 @@ def test_exact_event_match_boolean(self) -> None:
442441
"""Check that exact_event_match conditions work as expected for booleans."""
443442

444443
# Test against a True boolean value.
445-
condition = {
446-
"kind": "com.beeper.msc3758.exact_event_match",
447-
"key": "content.value",
448-
"value": True,
449-
}
444+
condition = {"kind": "event_property_is", "key": "content.value", "value": True}
450445
self._assert_matches(
451446
condition,
452447
{"value": True},
@@ -466,7 +461,7 @@ def test_exact_event_match_boolean(self) -> None:
466461

467462
# Test against a False boolean value.
468463
condition = {
469-
"kind": "com.beeper.msc3758.exact_event_match",
464+
"kind": "event_property_is",
470465
"key": "content.value",
471466
"value": False,
472467
}
@@ -491,11 +486,7 @@ def test_exact_event_match_boolean(self) -> None:
491486
def test_exact_event_match_null(self) -> None:
492487
"""Check that exact_event_match conditions work as expected for null."""
493488

494-
condition = {
495-
"kind": "com.beeper.msc3758.exact_event_match",
496-
"key": "content.value",
497-
"value": None,
498-
}
489+
condition = {"kind": "event_property_is", "key": "content.value", "value": None}
499490
self._assert_matches(
500491
condition,
501492
{"value": None},
@@ -511,11 +502,7 @@ def test_exact_event_match_null(self) -> None:
511502
def test_exact_event_match_integer(self) -> None:
512503
"""Check that exact_event_match conditions work as expected for integers."""
513504

514-
condition = {
515-
"kind": "com.beeper.msc3758.exact_event_match",
516-
"key": "content.value",
517-
"value": 1,
518-
}
505+
condition = {"kind": "event_property_is", "key": "content.value", "value": 1}
519506
self._assert_matches(
520507
condition,
521508
{"value": 1},

0 commit comments

Comments
 (0)