From 23c1dc0cdf4c82244e7ab96500e0ed74aedfc629 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Fri, 6 Jan 2023 19:12:45 +0000 Subject: [PATCH 01/10] Add an experimental config option for MSC3930 --- synapse/config/experimental.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/synapse/config/experimental.py b/synapse/config/experimental.py index 0f3870bfe18e..d0e41e6e089c 100644 --- a/synapse/config/experimental.py +++ b/synapse/config/experimental.py @@ -127,6 +127,9 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None: "msc3886_endpoint", None ) + # MSC3930: Push rules for MSC3391 polls + self.msc3930_enabled: bool = experimental.get("msc3930_enabled", False) + # MSC3912: Relation-based redactions. self.msc3912_enabled: bool = experimental.get("msc3912_enabled", False) From f9f3ea185ff873fe78e78ed1148421383e92d5a0 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Thu, 5 Jan 2023 17:00:04 +0000 Subject: [PATCH 02/10] Implement MSC3930: Polls push rules & notifications --- rust/src/push/base_rules.rs | 78 ++++++++++++++++++++- rust/src/push/mod.rs | 13 ++++ stubs/synapse/synapse_rust/push.pyi | 1 + synapse/push/bulk_push_rule_evaluator.py | 1 + synapse/storage/databases/main/push_rule.py | 1 + 5 files changed, 93 insertions(+), 1 deletion(-) diff --git a/rust/src/push/base_rules.rs b/rust/src/push/base_rules.rs index 35129691ca43..5bfa7a213afb 100644 --- a/rust/src/push/base_rules.rs +++ b/rust/src/push/base_rules.rs @@ -1,4 +1,4 @@ -// Copyright 2022 The Matrix.org Foundation C.I.C. +// Copyright 2022, 2023 The Matrix.org Foundation C.I.C. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -208,6 +208,20 @@ pub const BASE_APPEND_OVERRIDE_RULES: &[PushRule] = &[ default: true, default_enabled: true, }, + PushRule { + rule_id: Cow::Borrowed("global/override/.org.matrix.msc3930.rule.poll_response"), + priority_class: 5, + conditions: Cow::Borrowed(&[ + Condition::Known(KnownCondition::EventMatch(EventMatchCondition { + key: Cow::Borrowed("type"), + pattern: Some(Cow::Borrowed("org.matrix.msc3381.poll.response")), + pattern_type: None, + })), + ]), + actions: Cow::Borrowed(&[]), + default: true, + default_enabled: true, + }, ]; pub const BASE_APPEND_CONTENT_RULES: &[PushRule] = &[PushRule { @@ -596,6 +610,68 @@ pub const BASE_APPEND_UNDERRIDE_RULES: &[PushRule] = &[ default: true, default_enabled: true, }, + PushRule { + rule_id: Cow::Borrowed("global/underride/.org.matrix.msc3930.rule.poll_start_one_to_one"), + priority_class: 1, + conditions: Cow::Borrowed(&[ + Condition::Known(KnownCondition::RoomMemberCount { + is: Some(Cow::Borrowed("2")), + }), + Condition::Known(KnownCondition::EventMatch(EventMatchCondition { + key: Cow::Borrowed("type"), + pattern: Some(Cow::Borrowed("org.matrix.msc3381.poll.start")), + pattern_type: None, + })), + ]), + actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION]), + default: true, + default_enabled: true, + }, + PushRule { + rule_id: Cow::Borrowed("global/underride/.org.matrix.msc3930.rule.poll_start"), + priority_class: 1, + conditions: Cow::Borrowed(&[ + Condition::Known(KnownCondition::EventMatch(EventMatchCondition { + key: Cow::Borrowed("type"), + pattern: Some(Cow::Borrowed("org.matrix.msc3381.poll.start")), + pattern_type: None, + })), + ]), + actions: Cow::Borrowed(&[Action::Notify]), + default: true, + default_enabled: true, + }, + PushRule { + rule_id: Cow::Borrowed("global/underride/.org.matrix.msc3930.rule.poll_end_one_to_one"), + priority_class: 1, + conditions: Cow::Borrowed(&[ + Condition::Known(KnownCondition::RoomMemberCount { + is: Some(Cow::Borrowed("2")), + }), + Condition::Known(KnownCondition::EventMatch(EventMatchCondition { + key: Cow::Borrowed("type"), + pattern: Some(Cow::Borrowed("org.matrix.msc3381.poll.end")), + pattern_type: None, + })), + ]), + actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION]), + default: true, + default_enabled: true, + }, + PushRule { + rule_id: Cow::Borrowed("global/underride/.org.matrix.msc3930.rule.poll_end"), + priority_class: 1, + conditions: Cow::Borrowed(&[ + Condition::Known(KnownCondition::EventMatch(EventMatchCondition { + key: Cow::Borrowed("type"), + pattern: Some(Cow::Borrowed("org.matrix.msc3381.poll.end")), + pattern_type: None, + })), + ]), + actions: Cow::Borrowed(&[Action::Notify]), + default: true, + default_enabled: true, + }, ]; lazy_static! { diff --git a/rust/src/push/mod.rs b/rust/src/push/mod.rs index 2e9d3e38a17b..8ab0c9719dc2 100644 --- a/rust/src/push/mod.rs +++ b/rust/src/push/mod.rs @@ -411,6 +411,7 @@ impl PushRules { pub struct FilteredPushRules { push_rules: PushRules, enabled_map: BTreeMap, + msc3930_enabled: bool, msc3664_enabled: bool, msc1767_enabled: bool, } @@ -421,12 +422,14 @@ impl FilteredPushRules { pub fn py_new( push_rules: PushRules, enabled_map: BTreeMap, + msc3930_enabled: bool, msc3664_enabled: bool, msc1767_enabled: bool, ) -> Self { Self { push_rules, enabled_map, + msc3930_enabled, msc3664_enabled, msc1767_enabled, } @@ -447,6 +450,16 @@ impl FilteredPushRules { .iter() .filter(|rule| { // Ignore disabled experimental push rules + if !self.msc3930_enabled + && (rule.rule_id == "global/override/.org.matrix.msc3930.rule.poll_response" + || rule.rule_id == "global/underride/.org.matrix.msc3930.rule.poll_start_one_to_one" + || rule.rule_id == "global/underride/.org.matrix.msc3930.rule.poll_start" + || rule.rule_id == "global/underride/.org.matrix.msc3930.rule.poll_end_one_to_one" + || rule.rule_id == "global/underride/.org.matrix.msc3930.rule.poll_end") + { + return false; + } + if !self.msc3664_enabled && rule.rule_id == "global/override/.im.nheko.msc3664.reply" { diff --git a/stubs/synapse/synapse_rust/push.pyi b/stubs/synapse/synapse_rust/push.pyi index dab5d4aff7ce..75e33edc39db 100644 --- a/stubs/synapse/synapse_rust/push.pyi +++ b/stubs/synapse/synapse_rust/push.pyi @@ -29,6 +29,7 @@ class FilteredPushRules: self, push_rules: PushRules, enabled_map: Dict[str, bool], + msc3930_enabled: bool, msc3664_enabled: bool, msc1767_enabled: bool, ): ... diff --git a/synapse/push/bulk_push_rule_evaluator.py b/synapse/push/bulk_push_rule_evaluator.py index f27ba64d5365..de8e56b6bff5 100644 --- a/synapse/push/bulk_push_rule_evaluator.py +++ b/synapse/push/bulk_push_rule_evaluator.py @@ -348,6 +348,7 @@ async def _action_for_event_by_user( sender_power_level, notification_levels, related_events, + self.hs.config.experimental.msc3930_enabled, self._related_event_match_enabled, event.room_version.msc3931_push_features, self.hs.config.experimental.msc1767_enabled, # MSC3931 flag diff --git a/synapse/storage/databases/main/push_rule.py b/synapse/storage/databases/main/push_rule.py index d4e4b777da95..af9e0c23f0f8 100644 --- a/synapse/storage/databases/main/push_rule.py +++ b/synapse/storage/databases/main/push_rule.py @@ -86,6 +86,7 @@ def _load_rules( filtered_rules = FilteredPushRules( push_rules, enabled_map, + msc3930_enabled=experimental_config.msc3930_enabled, msc3664_enabled=experimental_config.msc3664_enabled, msc1767_enabled=experimental_config.msc1767_enabled, ) From 206349e061e16da583b8f297c80c5325c86d5201 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Fri, 6 Jan 2023 18:47:28 +0000 Subject: [PATCH 03/10] Enable support for msc3930 in synapse's complement runs --- docker/complement/conf/workers-shared-extra.yaml.j2 | 2 ++ scripts-dev/complement.sh | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docker/complement/conf/workers-shared-extra.yaml.j2 b/docker/complement/conf/workers-shared-extra.yaml.j2 index cb839fed078d..55f769380cf6 100644 --- a/docker/complement/conf/workers-shared-extra.yaml.j2 +++ b/docker/complement/conf/workers-shared-extra.yaml.j2 @@ -104,6 +104,8 @@ experimental_features: msc3874_enabled: true # Enable removing account data support msc3391_enabled: true + # Enable push rules for polls + msc3930_enabled: true server_notices: system_mxid_localpart: _server diff --git a/scripts-dev/complement.sh b/scripts-dev/complement.sh index 51d1bac6183c..59152bdfc9a8 100755 --- a/scripts-dev/complement.sh +++ b/scripts-dev/complement.sh @@ -190,7 +190,7 @@ fi extra_test_args=() -test_tags="synapse_blacklist,msc3787,msc3874,msc3391" +test_tags="synapse_blacklist,msc3787,msc3874,msc3391,msc3930" # All environment variables starting with PASS_ will be shared. # (The prefix is stripped off before reaching the container.) From ee1b3faf072e905bec6e543239f379bad2725479 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Fri, 6 Jan 2023 19:36:04 +0000 Subject: [PATCH 04/10] changelog --- changelog.d/14787.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/14787.feature diff --git a/changelog.d/14787.feature b/changelog.d/14787.feature new file mode 100644 index 000000000000..d0c5b71f60a3 --- /dev/null +++ b/changelog.d/14787.feature @@ -0,0 +1 @@ +Implement experimental support for MSC3930. \ No newline at end of file From 33e6e916dc0f79aad770961634ad5e1f32945cf8 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Wed, 11 Jan 2023 14:31:07 +0000 Subject: [PATCH 05/10] Fix up arguments to FilteredPushRules, PushRuleEvaluator --- rust/benches/evaluator.rs | 2 +- rust/src/push/evaluator.rs | 2 +- synapse/push/bulk_push_rule_evaluator.py | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/rust/benches/evaluator.rs b/rust/benches/evaluator.rs index 442a79348fcf..7321f6c5313b 100644 --- a/rust/benches/evaluator.rs +++ b/rust/benches/evaluator.rs @@ -151,7 +151,7 @@ fn bench_eval_message(b: &mut Bencher) { .unwrap(); let rules = - FilteredPushRules::py_new(PushRules::new(Vec::new()), Default::default(), false, false); + FilteredPushRules::py_new(PushRules::new(Vec::new()), Default::default(), false, false, false); b.iter(|| eval.run(&rules, Some("bob"), Some("person"))); } diff --git a/rust/src/push/evaluator.rs b/rust/src/push/evaluator.rs index c901c0fbcc60..6eae1e4972b3 100644 --- a/rust/src/push/evaluator.rs +++ b/rust/src/push/evaluator.rs @@ -483,7 +483,7 @@ fn test_requires_room_version_supports_condition() { }; let rules = PushRules::new(vec![custom_rule]); result = evaluator.run( - &FilteredPushRules::py_new(rules, BTreeMap::new(), true, true), + &FilteredPushRules::py_new(rules, BTreeMap::new(), false, true, true), None, None, ); diff --git a/synapse/push/bulk_push_rule_evaluator.py b/synapse/push/bulk_push_rule_evaluator.py index de8e56b6bff5..f27ba64d5365 100644 --- a/synapse/push/bulk_push_rule_evaluator.py +++ b/synapse/push/bulk_push_rule_evaluator.py @@ -348,7 +348,6 @@ async def _action_for_event_by_user( sender_power_level, notification_levels, related_events, - self.hs.config.experimental.msc3930_enabled, self._related_event_match_enabled, event.room_version.msc3931_push_features, self.hs.config.experimental.msc1767_enabled, # MSC3931 flag From b63b2ff98269d629db93aafa835725360efdada2 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Wed, 11 Jan 2023 14:41:39 +0000 Subject: [PATCH 06/10] Organise MSC* arguments alphabetically --- .../conf/workers-shared-extra.yaml.j2 | 4 +-- rust/src/push/mod.rs | 29 ++++++++++--------- stubs/synapse/synapse_rust/push.pyi | 4 +-- synapse/storage/databases/main/push_rule.py | 4 +-- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/docker/complement/conf/workers-shared-extra.yaml.j2 b/docker/complement/conf/workers-shared-extra.yaml.j2 index 55f769380cf6..b1d796aa43a2 100644 --- a/docker/complement/conf/workers-shared-extra.yaml.j2 +++ b/docker/complement/conf/workers-shared-extra.yaml.j2 @@ -100,10 +100,10 @@ experimental_features: # client-side support for partial state in /send_join responses faster_joins: true {% endif %} - # Filtering /messages by relation type. - msc3874_enabled: true # Enable removing account data support msc3391_enabled: true + # Filtering /messages by relation type. + msc3874_enabled: true # Enable push rules for polls msc3930_enabled: true diff --git a/rust/src/push/mod.rs b/rust/src/push/mod.rs index 8ab0c9719dc2..3cdcf1538eba 100644 --- a/rust/src/push/mod.rs +++ b/rust/src/push/mod.rs @@ -411,9 +411,9 @@ impl PushRules { pub struct FilteredPushRules { push_rules: PushRules, enabled_map: BTreeMap, - msc3930_enabled: bool, - msc3664_enabled: bool, msc1767_enabled: bool, + msc3664_enabled: bool, + msc3930_enabled: bool, } #[pymethods] @@ -422,16 +422,16 @@ impl FilteredPushRules { pub fn py_new( push_rules: PushRules, enabled_map: BTreeMap, - msc3930_enabled: bool, - msc3664_enabled: bool, msc1767_enabled: bool, + msc3664_enabled: bool, + msc3930_enabled: bool, ) -> Self { Self { push_rules, enabled_map, - msc3930_enabled, - msc3664_enabled, msc1767_enabled, + msc3664_enabled, + msc3930_enabled, } } @@ -450,13 +450,8 @@ impl FilteredPushRules { .iter() .filter(|rule| { // Ignore disabled experimental push rules - if !self.msc3930_enabled - && (rule.rule_id == "global/override/.org.matrix.msc3930.rule.poll_response" - || rule.rule_id == "global/underride/.org.matrix.msc3930.rule.poll_start_one_to_one" - || rule.rule_id == "global/underride/.org.matrix.msc3930.rule.poll_start" - || rule.rule_id == "global/underride/.org.matrix.msc3930.rule.poll_end_one_to_one" - || rule.rule_id == "global/underride/.org.matrix.msc3930.rule.poll_end") - { + + if !self.msc1767_enabled && rule.rule_id.contains("org.matrix.msc1767") { return false; } @@ -466,7 +461,13 @@ impl FilteredPushRules { return false; } - if !self.msc1767_enabled && rule.rule_id.contains("org.matrix.msc1767") { + if !self.msc3930_enabled + && (rule.rule_id == "global/override/.org.matrix.msc3930.rule.poll_response" + || rule.rule_id == "global/underride/.org.matrix.msc3930.rule.poll_start_one_to_one" + || rule.rule_id == "global/underride/.org.matrix.msc3930.rule.poll_start" + || rule.rule_id == "global/underride/.org.matrix.msc3930.rule.poll_end_one_to_one" + || rule.rule_id == "global/underride/.org.matrix.msc3930.rule.poll_end") + { return false; } diff --git a/stubs/synapse/synapse_rust/push.pyi b/stubs/synapse/synapse_rust/push.pyi index 75e33edc39db..9de14f4ce272 100644 --- a/stubs/synapse/synapse_rust/push.pyi +++ b/stubs/synapse/synapse_rust/push.pyi @@ -29,9 +29,9 @@ class FilteredPushRules: self, push_rules: PushRules, enabled_map: Dict[str, bool], - msc3930_enabled: bool, - msc3664_enabled: bool, msc1767_enabled: bool, + msc3664_enabled: bool, + msc3930_enabled: bool, ): ... def rules(self) -> Collection[Tuple[PushRule, bool]]: ... diff --git a/synapse/storage/databases/main/push_rule.py b/synapse/storage/databases/main/push_rule.py index af9e0c23f0f8..911aee87cc80 100644 --- a/synapse/storage/databases/main/push_rule.py +++ b/synapse/storage/databases/main/push_rule.py @@ -86,9 +86,9 @@ def _load_rules( filtered_rules = FilteredPushRules( push_rules, enabled_map, - msc3930_enabled=experimental_config.msc3930_enabled, - msc3664_enabled=experimental_config.msc3664_enabled, msc1767_enabled=experimental_config.msc1767_enabled, + msc3664_enabled=experimental_config.msc3664_enabled, + msc3930_enabled=experimental_config.msc3930_enabled, ) return filtered_rules From 595483304aeef75bd2102c90033ccc7f4eea959a Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Wed, 11 Jan 2023 15:13:28 +0000 Subject: [PATCH 07/10] Rename msc3930_enabled -> msc3381_polls_enabled --- changelog.d/14787.feature | 2 +- docker/complement/conf/workers-shared-extra.yaml.j2 | 4 ++-- rust/src/push/mod.rs | 8 ++++---- stubs/synapse/synapse_rust/push.pyi | 2 +- synapse/config/experimental.py | 8 ++++++-- synapse/storage/databases/main/push_rule.py | 2 +- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/changelog.d/14787.feature b/changelog.d/14787.feature index d0c5b71f60a3..6a340350470c 100644 --- a/changelog.d/14787.feature +++ b/changelog.d/14787.feature @@ -1 +1 @@ -Implement experimental support for MSC3930. \ No newline at end of file +Implement experimental support for MSC3930: Push rules for (MSC3381) Polls. \ No newline at end of file diff --git a/docker/complement/conf/workers-shared-extra.yaml.j2 b/docker/complement/conf/workers-shared-extra.yaml.j2 index b1d796aa43a2..5f0404ff04ae 100644 --- a/docker/complement/conf/workers-shared-extra.yaml.j2 +++ b/docker/complement/conf/workers-shared-extra.yaml.j2 @@ -100,12 +100,12 @@ experimental_features: # client-side support for partial state in /send_join responses faster_joins: true {% endif %} + # Enable support for polls + msc3381_polls_enabled: true # Enable removing account data support msc3391_enabled: true # Filtering /messages by relation type. msc3874_enabled: true - # Enable push rules for polls - msc3930_enabled: true server_notices: system_mxid_localpart: _server diff --git a/rust/src/push/mod.rs b/rust/src/push/mod.rs index 3cdcf1538eba..7949571e96d9 100644 --- a/rust/src/push/mod.rs +++ b/rust/src/push/mod.rs @@ -412,8 +412,8 @@ pub struct FilteredPushRules { push_rules: PushRules, enabled_map: BTreeMap, msc1767_enabled: bool, + msc3381_polls_enabled: bool, msc3664_enabled: bool, - msc3930_enabled: bool, } #[pymethods] @@ -423,15 +423,15 @@ impl FilteredPushRules { push_rules: PushRules, enabled_map: BTreeMap, msc1767_enabled: bool, + msc3381_polls_enabled: bool, msc3664_enabled: bool, - msc3930_enabled: bool, ) -> Self { Self { push_rules, enabled_map, msc1767_enabled, + msc3381_polls_enabled, msc3664_enabled, - msc3930_enabled, } } @@ -461,7 +461,7 @@ impl FilteredPushRules { return false; } - if !self.msc3930_enabled + if !self.msc3381_polls_enabled && (rule.rule_id == "global/override/.org.matrix.msc3930.rule.poll_response" || rule.rule_id == "global/underride/.org.matrix.msc3930.rule.poll_start_one_to_one" || rule.rule_id == "global/underride/.org.matrix.msc3930.rule.poll_start" diff --git a/stubs/synapse/synapse_rust/push.pyi b/stubs/synapse/synapse_rust/push.pyi index 9de14f4ce272..7edb1437b894 100644 --- a/stubs/synapse/synapse_rust/push.pyi +++ b/stubs/synapse/synapse_rust/push.pyi @@ -30,8 +30,8 @@ class FilteredPushRules: push_rules: PushRules, enabled_map: Dict[str, bool], msc1767_enabled: bool, + msc3381_polls_enabled: bool, msc3664_enabled: bool, - msc3930_enabled: bool, ): ... def rules(self) -> Collection[Tuple[PushRule, bool]]: ... diff --git a/synapse/config/experimental.py b/synapse/config/experimental.py index d0e41e6e089c..2c21685dbdd4 100644 --- a/synapse/config/experimental.py +++ b/synapse/config/experimental.py @@ -127,8 +127,12 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None: "msc3886_endpoint", None ) - # MSC3930: Push rules for MSC3391 polls - self.msc3930_enabled: bool = experimental.get("msc3930_enabled", False) + # MSC3381: Polls. + # In practice, supporting polls in Synapse only requires an implementation of + # MSC3930: Push rules for MSC3391 polls; which is what this option enables. + self.msc3381_polls_enabled: bool = experimental.get( + "msc3381_polls_enabled", False + ) # MSC3912: Relation-based redactions. self.msc3912_enabled: bool = experimental.get("msc3912_enabled", False) diff --git a/synapse/storage/databases/main/push_rule.py b/synapse/storage/databases/main/push_rule.py index 911aee87cc80..03182887d138 100644 --- a/synapse/storage/databases/main/push_rule.py +++ b/synapse/storage/databases/main/push_rule.py @@ -88,7 +88,7 @@ def _load_rules( enabled_map, msc1767_enabled=experimental_config.msc1767_enabled, msc3664_enabled=experimental_config.msc3664_enabled, - msc3930_enabled=experimental_config.msc3930_enabled, + msc3381_polls_enabled=experimental_config.msc3381_polls_enabled, ) return filtered_rules From f96f86c5b12dcc1901dad728f7b33022f5cfa941 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Wed, 11 Jan 2023 15:21:55 +0000 Subject: [PATCH 08/10] Catch a behavioural change after argument order shuffling --- rust/src/push/evaluator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/src/push/evaluator.rs b/rust/src/push/evaluator.rs index 6eae1e4972b3..0242ee1c5ffc 100644 --- a/rust/src/push/evaluator.rs +++ b/rust/src/push/evaluator.rs @@ -483,7 +483,7 @@ fn test_requires_room_version_supports_condition() { }; let rules = PushRules::new(vec![custom_rule]); result = evaluator.run( - &FilteredPushRules::py_new(rules, BTreeMap::new(), false, true, true), + &FilteredPushRules::py_new(rules, BTreeMap::new(), true, false, true), None, None, ); From 78bf8b0a5d911582d01d18a9cff1a6e16e9ae626 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Wed, 11 Jan 2023 15:22:38 +0000 Subject: [PATCH 09/10] Run cargo fmt --- rust/benches/evaluator.rs | 9 +++++++-- rust/src/push/base_rules.rs | 24 ++++++++++++------------ rust/src/push/mod.rs | 10 ++++++---- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/rust/benches/evaluator.rs b/rust/benches/evaluator.rs index 7321f6c5313b..8c28bb0af3dc 100644 --- a/rust/benches/evaluator.rs +++ b/rust/benches/evaluator.rs @@ -150,8 +150,13 @@ fn bench_eval_message(b: &mut Bencher) { ) .unwrap(); - let rules = - FilteredPushRules::py_new(PushRules::new(Vec::new()), Default::default(), false, false, false); + let rules = FilteredPushRules::py_new( + PushRules::new(Vec::new()), + Default::default(), + false, + false, + false, + ); b.iter(|| eval.run(&rules, Some("bob"), Some("person"))); } diff --git a/rust/src/push/base_rules.rs b/rust/src/push/base_rules.rs index 5bfa7a213afb..9140a69bb654 100644 --- a/rust/src/push/base_rules.rs +++ b/rust/src/push/base_rules.rs @@ -211,13 +211,13 @@ pub const BASE_APPEND_OVERRIDE_RULES: &[PushRule] = &[ PushRule { rule_id: Cow::Borrowed("global/override/.org.matrix.msc3930.rule.poll_response"), priority_class: 5, - conditions: Cow::Borrowed(&[ - Condition::Known(KnownCondition::EventMatch(EventMatchCondition { + conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch( + EventMatchCondition { key: Cow::Borrowed("type"), pattern: Some(Cow::Borrowed("org.matrix.msc3381.poll.response")), pattern_type: None, - })), - ]), + }, + ))]), actions: Cow::Borrowed(&[]), default: true, default_enabled: true, @@ -630,13 +630,13 @@ pub const BASE_APPEND_UNDERRIDE_RULES: &[PushRule] = &[ PushRule { rule_id: Cow::Borrowed("global/underride/.org.matrix.msc3930.rule.poll_start"), priority_class: 1, - conditions: Cow::Borrowed(&[ - Condition::Known(KnownCondition::EventMatch(EventMatchCondition { + conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch( + EventMatchCondition { key: Cow::Borrowed("type"), pattern: Some(Cow::Borrowed("org.matrix.msc3381.poll.start")), pattern_type: None, - })), - ]), + }, + ))]), actions: Cow::Borrowed(&[Action::Notify]), default: true, default_enabled: true, @@ -661,13 +661,13 @@ pub const BASE_APPEND_UNDERRIDE_RULES: &[PushRule] = &[ PushRule { rule_id: Cow::Borrowed("global/underride/.org.matrix.msc3930.rule.poll_end"), priority_class: 1, - conditions: Cow::Borrowed(&[ - Condition::Known(KnownCondition::EventMatch(EventMatchCondition { + conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch( + EventMatchCondition { key: Cow::Borrowed("type"), pattern: Some(Cow::Borrowed("org.matrix.msc3381.poll.end")), pattern_type: None, - })), - ]), + }, + ))]), actions: Cow::Borrowed(&[Action::Notify]), default: true, default_enabled: true, diff --git a/rust/src/push/mod.rs b/rust/src/push/mod.rs index 7949571e96d9..4a8041fe4cb7 100644 --- a/rust/src/push/mod.rs +++ b/rust/src/push/mod.rs @@ -463,10 +463,12 @@ impl FilteredPushRules { if !self.msc3381_polls_enabled && (rule.rule_id == "global/override/.org.matrix.msc3930.rule.poll_response" - || rule.rule_id == "global/underride/.org.matrix.msc3930.rule.poll_start_one_to_one" - || rule.rule_id == "global/underride/.org.matrix.msc3930.rule.poll_start" - || rule.rule_id == "global/underride/.org.matrix.msc3930.rule.poll_end_one_to_one" - || rule.rule_id == "global/underride/.org.matrix.msc3930.rule.poll_end") + || rule.rule_id + == "global/underride/.org.matrix.msc3930.rule.poll_start_one_to_one" + || rule.rule_id == "global/underride/.org.matrix.msc3930.rule.poll_start" + || rule.rule_id + == "global/underride/.org.matrix.msc3930.rule.poll_end_one_to_one" + || rule.rule_id == "global/underride/.org.matrix.msc3930.rule.poll_end") { return false; } From 0527397f70b0def8bd64a2bad6c99047e9235cd1 Mon Sep 17 00:00:00 2001 From: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> Date: Thu, 12 Jan 2023 18:29:46 +0000 Subject: [PATCH 10/10] Simplify experimental option checking when filtering push rules Co-authored-by: Patrick Cloke --- rust/src/push/mod.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/rust/src/push/mod.rs b/rust/src/push/mod.rs index 4a8041fe4cb7..842b13c88b2c 100644 --- a/rust/src/push/mod.rs +++ b/rust/src/push/mod.rs @@ -461,15 +461,7 @@ impl FilteredPushRules { return false; } - if !self.msc3381_polls_enabled - && (rule.rule_id == "global/override/.org.matrix.msc3930.rule.poll_response" - || rule.rule_id - == "global/underride/.org.matrix.msc3930.rule.poll_start_one_to_one" - || rule.rule_id == "global/underride/.org.matrix.msc3930.rule.poll_start" - || rule.rule_id - == "global/underride/.org.matrix.msc3930.rule.poll_end_one_to_one" - || rule.rule_id == "global/underride/.org.matrix.msc3930.rule.poll_end") - { + if !self.msc3381_polls_enabled && rule.rule_id.contains("org.matrix.msc3930") { return false; }