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

Commit

Permalink
Update intentional mentions (MSC3952) to depend on exact_event_match (
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed Feb 9, 2023
1 parent 4450b80 commit 4b67af3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog.d/15037.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update [MSC3952](https://github.com/matrix-org/matrix-spec-proposals/pull/3952) support based on changes to the MSC.
7 changes: 5 additions & 2 deletions rust/src/push/base_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ use lazy_static::lazy_static;
use serde_json::Value;

use super::KnownCondition;
use crate::push::Action;
use crate::push::Condition;
use crate::push::EventMatchCondition;
use crate::push::PushRule;
use crate::push::RelatedEventMatchCondition;
use crate::push::SetTweak;
use crate::push::TweakValue;
use crate::push::{Action, ExactEventMatchCondition, SimpleJsonValue};

const HIGHLIGHT_ACTION: Action = Action::SetTweak(SetTweak {
set_tweak: Cow::Borrowed("highlight"),
Expand Down Expand Up @@ -168,7 +168,10 @@ pub const BASE_APPEND_OVERRIDE_RULES: &[PushRule] = &[
rule_id: Cow::Borrowed(".org.matrix.msc3952.is_room_mention"),
priority_class: 5,
conditions: Cow::Borrowed(&[
Condition::Known(KnownCondition::IsRoomMention),
Condition::Known(KnownCondition::ExactEventMatch(ExactEventMatchCondition {
key: Cow::Borrowed("content.org.matrix.msc3952.mentions.room"),
value: Cow::Borrowed(&SimpleJsonValue::Bool(true)),
})),
Condition::Known(KnownCondition::SenderNotificationPermission {
key: Cow::Borrowed("room"),
}),
Expand Down
7 changes: 4 additions & 3 deletions synapse/config/experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,10 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
"msc3783_escape_event_match_key", False
)

# MSC3952: Intentional mentions
self.msc3952_intentional_mentions = experimental.get(
"msc3952_intentional_mentions", False
# MSC3952: Intentional mentions, this depends on MSC3758.
self.msc3952_intentional_mentions = (
experimental.get("msc3952_intentional_mentions", False)
and self.msc3758_exact_event_match
)

# MSC3959: Do not generate notifications for edits.
Expand Down
11 changes: 9 additions & 2 deletions tests/push/test_bulk_push_rule_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,14 @@ def _create_and_process(
)
return len(result) > 0

@override_config({"experimental_features": {"msc3952_intentional_mentions": True}})
@override_config(
{
"experimental_features": {
"msc3758_exact_event_match": True,
"msc3952_intentional_mentions": True,
}
}
)
def test_user_mentions(self) -> None:
"""Test the behavior of an event which includes invalid user mentions."""
bulk_evaluator = BulkPushRuleEvaluator(self.hs)
Expand Down Expand Up @@ -323,7 +330,7 @@ def test_user_mentions(self) -> None:
)
)

@override_config({"experimental_features": {"msc3952_intentional_mentions": True}})
@override_config({"experimental_features": {"msc3758_exact_event_match": True, "msc3952_intentional_mentions": True}})
def test_room_mentions(self) -> None:
"""Test the behavior of an event which includes invalid room mentions."""
bulk_evaluator = BulkPushRuleEvaluator(self.hs)
Expand Down

0 comments on commit 4b67af3

Please sign in to comment.