Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/19954.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add experimental support for [MSC4505](https://github.com/matrix-org/matrix-spec-proposals/pull/4505): push rules for live location sharing.
1 change: 1 addition & 0 deletions rust/benches/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ fn bench_eval_message(b: &mut Bencher) {
false,
false,
false,
false,
);

b.iter(|| eval.run(&rules, Some("bob"), Some("person"), None));
Expand Down
53 changes: 53 additions & 0 deletions rust/src/push/base_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,22 @@ pub const BASE_APPEND_OVERRIDE_RULES: &[PushRule] = &[
default: true,
default_enabled: true,
},
// MSC4505: explicitly suppress live location share beacon updates in unencrypted
// rooms (in encrypted rooms they arrive as m.room.encrypted and can only be
// suppressed client-side after decryption).
PushRule {
rule_id: Cow::Borrowed("global/override/.org.matrix.msc4505.rule.beacon"),
priority_class: 5,
conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
EventMatchCondition {
key: Cow::Borrowed("type"),
pattern: Cow::Borrowed("org.matrix.msc3672.beacon"),
},
))]),
actions: Cow::Borrowed(&[]),
default: true,
default_enabled: true,
},
];

pub const BASE_APPEND_CONTENT_RULES: &[PushRule] = &[PushRule {
Expand Down Expand Up @@ -721,6 +737,43 @@ pub const BASE_APPEND_UNDERRIDE_RULES: &[PushRule] = &[
default: true,
default_enabled: true,
},
PushRule {
rule_id: Cow::Borrowed("global/underride/.org.matrix.msc4505.rule.beacon_info_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: Cow::Borrowed("org.matrix.msc3672.beacon_info"),
})),
Condition::Known(KnownCondition::EventPropertyIs(EventPropertyIsCondition {
key: Cow::Borrowed("content.live"),
value: Cow::Owned(SimpleJsonValue::Bool(true)),
})),
]),
actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION]),
default: true,
default_enabled: true,
},
PushRule {
rule_id: Cow::Borrowed("global/underride/.org.matrix.msc4505.rule.beacon_info"),
priority_class: 1,
conditions: Cow::Borrowed(&[
Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
key: Cow::Borrowed("type"),
pattern: Cow::Borrowed("org.matrix.msc3672.beacon_info"),
})),
Condition::Known(KnownCondition::EventPropertyIs(EventPropertyIsCondition {
key: Cow::Borrowed("content.live"),
value: Cow::Owned(SimpleJsonValue::Bool(true)),
})),
]),
actions: Cow::Borrowed(&[Action::Notify]),
default: true,
default_enabled: true,
},
];

lazy_static! {
Expand Down
1 change: 1 addition & 0 deletions rust/src/push/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ fn test_requires_room_version_supports_condition() {
false,
false,
false,
false,
),
None,
None,
Expand Down
9 changes: 9 additions & 0 deletions rust/src/push/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ pub struct FilteredPushRules {
msc4028_push_encrypted_events: bool,
msc4210_enabled: bool,
msc4306_enabled: bool,
msc4505_enabled: bool,
}

#[pymethods]
Expand All @@ -574,6 +575,7 @@ impl FilteredPushRules {
msc4028_push_encrypted_events: bool,
msc4210_enabled: bool,
msc4306_enabled: bool,
msc4505_enabled: bool,
) -> Self {
Self {
push_rules,
Expand All @@ -584,6 +586,7 @@ impl FilteredPushRules {
msc4028_push_encrypted_events,
msc4210_enabled,
msc4306_enabled,
msc4505_enabled,
}
}

Expand Down Expand Up @@ -620,6 +623,12 @@ impl FilteredPushRules {
return false;
}

if !self.msc4505_enabled
&& rule.rule_id.contains("/.org.matrix.msc4505.rule.beacon")
{
return false;
}

if !self.msc4028_push_encrypted_events
&& rule.rule_id == "global/override/.org.matrix.msc4028.encrypted_event"
{
Expand Down
6 changes: 6 additions & 0 deletions synapse/config/experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ def read_config(
"msc3381_polls_enabled", False
)

# MSC4505: default push rules for live location sharing — notify on
# beacon_info start events (the MSC3672 state event), suppress beacon
# updates. Unstable rule ids: .org.matrix.msc4505.rule.beacon_info
# (_one_to_one) / .org.matrix.msc4505.rule.beacon.
self.msc4505_enabled: bool = experimental.get("msc4505_enabled", False)

# MSC3912: Relation-based redactions.
self.msc3912_enabled: bool = experimental.get("msc3912_enabled", False)

Expand Down
1 change: 1 addition & 0 deletions synapse/storage/databases/main/push_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def _load_rules(
msc4028_push_encrypted_events=experimental_config.msc4028_push_encrypted_events,
msc4210_enabled=experimental_config.msc4210_enabled,
msc4306_enabled=experimental_config.msc4306_enabled,
msc4505_enabled=experimental_config.msc4505_enabled,
)

return filtered_rules
Expand Down
1 change: 1 addition & 0 deletions synapse/synapse_rust/push.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class FilteredPushRules:
msc4028_push_encrypted_events: bool,
msc4210_enabled: bool,
msc4306_enabled: bool,
msc4505_enabled: bool,
): ...
def rules(self) -> Collection[tuple[PushRule, bool]]: ...

Expand Down
Loading