mirror of
https://github.com/element-hq/synapse.git
synced 2024-12-14 11:57:44 +00:00
Implement MSC3930: polls push rules (#14787)
This commit is contained in:
parent
2069231645
commit
a7b54ca8d8
10 changed files with 114 additions and 13 deletions
1
changelog.d/14787.feature
Normal file
1
changelog.d/14787.feature
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Implement experimental support for MSC3930: Push rules for (MSC3381) Polls.
|
|
@ -98,12 +98,14 @@ experimental_features:
|
||||||
# client-side support for partial state in /send_join responses
|
# client-side support for partial state in /send_join responses
|
||||||
faster_joins: true
|
faster_joins: true
|
||||||
{% endif %}
|
{% endif %}
|
||||||
# Filtering /messages by relation type.
|
# Enable support for polls
|
||||||
msc3874_enabled: true
|
msc3381_polls_enabled: true
|
||||||
# Enable deleting device-specific notification settings stored in account data
|
# Enable deleting device-specific notification settings stored in account data
|
||||||
msc3890_enabled: true
|
msc3890_enabled: true
|
||||||
# Enable removing account data support
|
# Enable removing account data support
|
||||||
msc3391_enabled: true
|
msc3391_enabled: true
|
||||||
|
# Filtering /messages by relation type.
|
||||||
|
msc3874_enabled: true
|
||||||
|
|
||||||
server_notices:
|
server_notices:
|
||||||
system_mxid_localpart: _server
|
system_mxid_localpart: _server
|
||||||
|
|
|
@ -150,8 +150,13 @@ fn bench_eval_message(b: &mut Bencher) {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let rules =
|
let rules = FilteredPushRules::py_new(
|
||||||
FilteredPushRules::py_new(PushRules::new(Vec::new()), Default::default(), false, false);
|
PushRules::new(Vec::new()),
|
||||||
|
Default::default(),
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
b.iter(|| eval.run(&rules, Some("bob"), Some("person")));
|
b.iter(|| eval.run(&rules, Some("bob"), Some("person")));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with 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: true,
|
||||||
default_enabled: 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 {
|
pub const BASE_APPEND_CONTENT_RULES: &[PushRule] = &[PushRule {
|
||||||
|
@ -596,6 +610,68 @@ pub const BASE_APPEND_UNDERRIDE_RULES: &[PushRule] = &[
|
||||||
default: true,
|
default: true,
|
||||||
default_enabled: 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! {
|
lazy_static! {
|
||||||
|
|
|
@ -483,7 +483,7 @@ fn test_requires_room_version_supports_condition() {
|
||||||
};
|
};
|
||||||
let rules = PushRules::new(vec![custom_rule]);
|
let rules = PushRules::new(vec![custom_rule]);
|
||||||
result = evaluator.run(
|
result = evaluator.run(
|
||||||
&FilteredPushRules::py_new(rules, BTreeMap::new(), true, true),
|
&FilteredPushRules::py_new(rules, BTreeMap::new(), true, false, true),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
|
@ -411,8 +411,9 @@ impl PushRules {
|
||||||
pub struct FilteredPushRules {
|
pub struct FilteredPushRules {
|
||||||
push_rules: PushRules,
|
push_rules: PushRules,
|
||||||
enabled_map: BTreeMap<String, bool>,
|
enabled_map: BTreeMap<String, bool>,
|
||||||
msc3664_enabled: bool,
|
|
||||||
msc1767_enabled: bool,
|
msc1767_enabled: bool,
|
||||||
|
msc3381_polls_enabled: bool,
|
||||||
|
msc3664_enabled: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pymethods]
|
#[pymethods]
|
||||||
|
@ -421,14 +422,16 @@ impl FilteredPushRules {
|
||||||
pub fn py_new(
|
pub fn py_new(
|
||||||
push_rules: PushRules,
|
push_rules: PushRules,
|
||||||
enabled_map: BTreeMap<String, bool>,
|
enabled_map: BTreeMap<String, bool>,
|
||||||
msc3664_enabled: bool,
|
|
||||||
msc1767_enabled: bool,
|
msc1767_enabled: bool,
|
||||||
|
msc3381_polls_enabled: bool,
|
||||||
|
msc3664_enabled: bool,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
push_rules,
|
push_rules,
|
||||||
enabled_map,
|
enabled_map,
|
||||||
msc3664_enabled,
|
|
||||||
msc1767_enabled,
|
msc1767_enabled,
|
||||||
|
msc3381_polls_enabled,
|
||||||
|
msc3664_enabled,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -447,13 +450,18 @@ impl FilteredPushRules {
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|rule| {
|
.filter(|rule| {
|
||||||
// Ignore disabled experimental push rules
|
// Ignore disabled experimental push rules
|
||||||
|
|
||||||
|
if !self.msc1767_enabled && rule.rule_id.contains("org.matrix.msc1767") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if !self.msc3664_enabled
|
if !self.msc3664_enabled
|
||||||
&& rule.rule_id == "global/override/.im.nheko.msc3664.reply"
|
&& rule.rule_id == "global/override/.im.nheko.msc3664.reply"
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.msc1767_enabled && rule.rule_id.contains("org.matrix.msc1767") {
|
if !self.msc3381_polls_enabled && rule.rule_id.contains("org.matrix.msc3930") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -190,7 +190,7 @@ fi
|
||||||
|
|
||||||
extra_test_args=()
|
extra_test_args=()
|
||||||
|
|
||||||
test_tags="synapse_blacklist,msc3787,msc3874,msc3890,msc3391"
|
test_tags="synapse_blacklist,msc3787,msc3874,msc3890,msc3391,msc3930"
|
||||||
|
|
||||||
# All environment variables starting with PASS_ will be shared.
|
# All environment variables starting with PASS_ will be shared.
|
||||||
# (The prefix is stripped off before reaching the container.)
|
# (The prefix is stripped off before reaching the container.)
|
||||||
|
|
|
@ -43,8 +43,9 @@ class FilteredPushRules:
|
||||||
self,
|
self,
|
||||||
push_rules: PushRules,
|
push_rules: PushRules,
|
||||||
enabled_map: Dict[str, bool],
|
enabled_map: Dict[str, bool],
|
||||||
msc3664_enabled: bool,
|
|
||||||
msc1767_enabled: bool,
|
msc1767_enabled: bool,
|
||||||
|
msc3381_polls_enabled: bool,
|
||||||
|
msc3664_enabled: bool,
|
||||||
): ...
|
): ...
|
||||||
def rules(self) -> Collection[Tuple[PushRule, bool]]: ...
|
def rules(self) -> Collection[Tuple[PushRule, bool]]: ...
|
||||||
|
|
||||||
|
|
|
@ -146,6 +146,13 @@ class ExperimentalConfig(Config):
|
||||||
"required to communicate account data deletions to clients."
|
"required to communicate account data deletions to clients."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# 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.
|
# MSC3912: Relation-based redactions.
|
||||||
self.msc3912_enabled: bool = experimental.get("msc3912_enabled", False)
|
self.msc3912_enabled: bool = experimental.get("msc3912_enabled", False)
|
||||||
|
|
||||||
|
|
|
@ -86,8 +86,9 @@ def _load_rules(
|
||||||
filtered_rules = FilteredPushRules(
|
filtered_rules = FilteredPushRules(
|
||||||
push_rules,
|
push_rules,
|
||||||
enabled_map,
|
enabled_map,
|
||||||
msc3664_enabled=experimental_config.msc3664_enabled,
|
|
||||||
msc1767_enabled=experimental_config.msc1767_enabled,
|
msc1767_enabled=experimental_config.msc1767_enabled,
|
||||||
|
msc3664_enabled=experimental_config.msc3664_enabled,
|
||||||
|
msc3381_polls_enabled=experimental_config.msc3381_polls_enabled,
|
||||||
)
|
)
|
||||||
|
|
||||||
return filtered_rules
|
return filtered_rules
|
||||||
|
|
Loading…
Reference in a new issue