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

Commit 17800a0

Browse files
authored
Implement MSC4028: push all encrypted events. (#16361)
This unstable push rule is implemented behind an experimental configuration flag.
1 parent 06f650f commit 17800a0

File tree

8 files changed

+31
-1
lines changed

8 files changed

+31
-1
lines changed

changelog.d/16361.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Experimental support for [MSC4028](https://github.com/matrix-org/matrix-spec-proposals/pull/4028) to push all encrypted events to clients.

rust/benches/evaluator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ fn bench_eval_message(b: &mut Bencher) {
197197
false,
198198
false,
199199
false,
200+
false,
200201
);
201202

202203
b.iter(|| eval.run(&rules, Some("bob"), Some("person")));

rust/src/push/base_rules.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@ pub const BASE_PREPEND_OVERRIDE_RULES: &[PushRule] = &[PushRule {
6363
}];
6464

6565
pub const BASE_APPEND_OVERRIDE_RULES: &[PushRule] = &[
66+
PushRule {
67+
rule_id: Cow::Borrowed("global/override/.org.matrix.msc4028.encrypted_event"),
68+
priority_class: 5,
69+
conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
70+
EventMatchCondition {
71+
key: Cow::Borrowed("type"),
72+
pattern: Cow::Borrowed("m.room.encrypted"),
73+
},
74+
))]),
75+
actions: Cow::Borrowed(&[Action::Notify]),
76+
default: true,
77+
default_enabled: false,
78+
},
6679
PushRule {
6780
rule_id: Cow::Borrowed("global/override/.m.rule.suppress_notices"),
6881
priority_class: 5,

rust/src/push/evaluator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ fn test_requires_room_version_supports_condition() {
564564
};
565565
let rules = PushRules::new(vec![custom_rule]);
566566
result = evaluator.run(
567-
&FilteredPushRules::py_new(rules, BTreeMap::new(), true, false, true),
567+
&FilteredPushRules::py_new(rules, BTreeMap::new(), true, false, true, false),
568568
None,
569569
None,
570570
);

rust/src/push/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ pub struct FilteredPushRules {
527527
msc1767_enabled: bool,
528528
msc3381_polls_enabled: bool,
529529
msc3664_enabled: bool,
530+
msc4028_push_encrypted_events: bool,
530531
}
531532

532533
#[pymethods]
@@ -538,13 +539,15 @@ impl FilteredPushRules {
538539
msc1767_enabled: bool,
539540
msc3381_polls_enabled: bool,
540541
msc3664_enabled: bool,
542+
msc4028_push_encrypted_events: bool,
541543
) -> Self {
542544
Self {
543545
push_rules,
544546
enabled_map,
545547
msc1767_enabled,
546548
msc3381_polls_enabled,
547549
msc3664_enabled,
550+
msc4028_push_encrypted_events,
548551
}
549552
}
550553

@@ -581,6 +584,12 @@ impl FilteredPushRules {
581584
return false;
582585
}
583586

587+
if !self.msc4028_push_encrypted_events
588+
&& rule.rule_id == "global/override/.org.matrix.msc4028.encrypted_event"
589+
{
590+
return false;
591+
}
592+
584593
true
585594
})
586595
.map(|r| {

stubs/synapse/synapse_rust/push.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class FilteredPushRules:
4646
msc1767_enabled: bool,
4747
msc3381_polls_enabled: bool,
4848
msc3664_enabled: bool,
49+
msc4028_push_encrypted_events: bool,
4950
): ...
5051
def rules(self) -> Collection[Tuple[PushRule, bool]]: ...
5152

synapse/config/experimental.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,3 +415,7 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
415415
LimitExceededError.include_retry_after_header = experimental.get(
416416
"msc4041_enabled", False
417417
)
418+
419+
self.msc4028_push_encrypted_events = experimental.get(
420+
"msc4028_push_encrypted_events", False
421+
)

synapse/storage/databases/main/push_rule.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def _load_rules(
8888
msc1767_enabled=experimental_config.msc1767_enabled,
8989
msc3664_enabled=experimental_config.msc3664_enabled,
9090
msc3381_polls_enabled=experimental_config.msc3381_polls_enabled,
91+
msc4028_push_encrypted_events=experimental_config.msc4028_push_encrypted_events,
9192
)
9293

9394
return filtered_rules

0 commit comments

Comments
 (0)