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

Commit b30a1a8

Browse files
committed
Remove the is_user_mention support.
1 parent 7c4a3a5 commit b30a1a8

File tree

6 files changed

+8
-78
lines changed

6 files changed

+8
-78
lines changed

rust/benches/evaluator.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ fn bench_match_exact(b: &mut Bencher) {
4444
let eval = PushRuleEvaluator::py_new(
4545
flattened_keys,
4646
false,
47-
BTreeSet::new(),
4847
10,
4948
Some(0),
5049
Default::default(),
@@ -92,7 +91,6 @@ fn bench_match_word(b: &mut Bencher) {
9291
let eval = PushRuleEvaluator::py_new(
9392
flattened_keys,
9493
false,
95-
BTreeSet::new(),
9694
10,
9795
Some(0),
9896
Default::default(),
@@ -140,7 +138,6 @@ fn bench_match_word_miss(b: &mut Bencher) {
140138
let eval = PushRuleEvaluator::py_new(
141139
flattened_keys,
142140
false,
143-
BTreeSet::new(),
144141
10,
145142
Some(0),
146143
Default::default(),
@@ -188,7 +185,6 @@ fn bench_eval_message(b: &mut Bencher) {
188185
let eval = PushRuleEvaluator::py_new(
189186
flattened_keys,
190187
false,
191-
BTreeSet::new(),
192188
10,
193189
Some(0),
194190
Default::default(),

rust/src/push/evaluator.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
use std::borrow::Cow;
16-
use std::collections::{BTreeMap, BTreeSet};
16+
use std::collections::BTreeMap;
1717

1818
use crate::push::{EventMatchPatternType, JsonValue};
1919
use anyhow::{Context, Error};
@@ -72,8 +72,6 @@ pub struct PushRuleEvaluator {
7272

7373
/// True if the event has a mentions property and MSC3952 support is enabled.
7474
has_mentions: bool,
75-
/// The user mentions that were part of the message.
76-
user_mentions: BTreeSet<String>,
7775

7876
/// The number of users in the room.
7977
room_member_count: u64,
@@ -114,7 +112,6 @@ impl PushRuleEvaluator {
114112
pub fn py_new(
115113
flattened_keys: BTreeMap<String, JsonValue>,
116114
has_mentions: bool,
117-
user_mentions: BTreeSet<String>,
118115
room_member_count: u64,
119116
sender_power_level: Option<i64>,
120117
notification_power_levels: BTreeMap<String, i64>,
@@ -134,7 +131,6 @@ impl PushRuleEvaluator {
134131
flattened_keys,
135132
body,
136133
has_mentions,
137-
user_mentions,
138134
room_member_count,
139135
notification_power_levels,
140136
sender_power_level,
@@ -335,13 +331,6 @@ impl PushRuleEvaluator {
335331
Cow::Borrowed(&SimpleJsonValue::Str(pattern.to_string())),
336332
)?
337333
}
338-
KnownCondition::IsUserMention => {
339-
if let Some(uid) = user_id {
340-
self.user_mentions.contains(uid)
341-
} else {
342-
false
343-
}
344-
}
345334
KnownCondition::ContainsDisplayName => {
346335
if let Some(dn) = display_name {
347336
if !dn.is_empty() {
@@ -529,7 +518,6 @@ fn push_rule_evaluator() {
529518
let evaluator = PushRuleEvaluator::py_new(
530519
flattened_keys,
531520
false,
532-
BTreeSet::new(),
533521
10,
534522
Some(0),
535523
BTreeMap::new(),
@@ -561,7 +549,6 @@ fn test_requires_room_version_supports_condition() {
561549
let evaluator = PushRuleEvaluator::py_new(
562550
flattened_keys,
563551
false,
564-
BTreeSet::new(),
565552
10,
566553
Some(0),
567554
BTreeMap::new(),

rust/src/push/mod.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,6 @@ pub enum KnownCondition {
346346
rename = "org.matrix.msc3966.exact_event_property_contains"
347347
)]
348348
ExactEventPropertyContainsType(ExactEventMatchTypeCondition),
349-
#[serde(rename = "org.matrix.msc3952.is_user_mention")]
350-
IsUserMention,
351349
ContainsDisplayName,
352350
RoomMemberCount {
353351
#[serde(skip_serializing_if = "Option::is_none")]
@@ -754,17 +752,6 @@ fn test_deserialize_unstable_msc3758_condition() {
754752
));
755753
}
756754

757-
#[test]
758-
fn test_deserialize_unstable_msc3952_user_condition() {
759-
let json = r#"{"kind":"org.matrix.msc3952.is_user_mention"}"#;
760-
761-
let condition: Condition = serde_json::from_str(json).unwrap();
762-
assert!(matches!(
763-
condition,
764-
Condition::Known(KnownCondition::IsUserMention)
765-
));
766-
}
767-
768755
#[test]
769756
fn test_deserialize_custom_condition() {
770757
let json = r#"{"kind":"custom_tag"}"#;

stubs/synapse/synapse_rust/push.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from typing import Any, Collection, Dict, Mapping, Optional, Sequence, Set, Tuple, Union
15+
from typing import Any, Collection, Dict, Mapping, Optional, Sequence, Tuple, Union
1616

1717
from synapse.types import JsonDict, JsonValue
1818

@@ -58,7 +58,6 @@ class PushRuleEvaluator:
5858
self,
5959
flattened_keys: Mapping[str, JsonValue],
6060
has_mentions: bool,
61-
user_mentions: Set[str],
6261
room_member_count: int,
6362
sender_power_level: Optional[int],
6463
notification_power_levels: Mapping[str, int],

synapse/push/bulk_push_rule_evaluator.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
Mapping,
2424
Optional,
2525
Sequence,
26-
Set,
2726
Tuple,
2827
Union,
2928
)
@@ -396,26 +395,17 @@ async def _action_for_event_by_user(
396395
del notification_levels[key]
397396

398397
# Pull out any user and room mentions.
399-
mentions = event.content.get(EventContentFields.MSC3952_MENTIONS)
400-
has_mentions = self._intentional_mentions_enabled and isinstance(mentions, dict)
401-
user_mentions: Set[str] = set()
402-
if has_mentions:
403-
# mypy seems to have lost the type even though it must be a dict here.
404-
assert isinstance(mentions, dict)
405-
# Remove out any non-string items and convert to a set.
406-
user_mentions_raw = mentions.get("user_ids")
407-
if isinstance(user_mentions_raw, list):
408-
user_mentions = set(
409-
filter(lambda item: isinstance(item, str), user_mentions_raw)
410-
)
398+
has_mentions = (
399+
self._intentional_mentions_enabled
400+
and EventContentFields.MSC3952_MENTIONS in event.content
401+
)
411402

412403
evaluator = PushRuleEvaluator(
413404
_flatten_dict(
414405
event,
415406
msc3873_escape_event_match_key=self.hs.config.experimental.msc3873_escape_event_match_key,
416407
),
417408
has_mentions,
418-
user_mentions,
419409
room_member_count,
420410
sender_power_level,
421411
notification_levels,

tests/push/test_push_rule_evaluator.py

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from typing import Any, Dict, List, Optional, Set, Union, cast
15+
from typing import Any, Dict, List, Optional, Union, cast
1616

1717
import frozendict
1818

@@ -147,8 +147,6 @@ def _get_evaluator(
147147
self,
148148
content: JsonMapping,
149149
*,
150-
has_mentions: bool = False,
151-
user_mentions: Optional[Set[str]] = None,
152150
related_events: Optional[JsonDict] = None,
153151
) -> PushRuleEvaluator:
154152
event = FrozenEvent(
@@ -167,8 +165,7 @@ def _get_evaluator(
167165
power_levels: Dict[str, Union[int, Dict[str, int]]] = {}
168166
return PushRuleEvaluator(
169167
_flatten_dict(event),
170-
has_mentions,
171-
user_mentions or set(),
168+
False,
172169
room_member_count,
173170
sender_power_level,
174171
cast(Dict[str, int], power_levels.get("notifications", {})),
@@ -204,32 +201,6 @@ def test_display_name(self) -> None:
204201
# A display name with spaces should work fine.
205202
self.assertTrue(evaluator.matches(condition, "@user:test", "foo bar"))
206203

207-
def test_user_mentions(self) -> None:
208-
"""Check for user mentions."""
209-
condition = {"kind": "org.matrix.msc3952.is_user_mention"}
210-
211-
# No mentions shouldn't match.
212-
evaluator = self._get_evaluator({}, has_mentions=True)
213-
self.assertFalse(evaluator.matches(condition, "@user:test", None))
214-
215-
# An empty set shouldn't match
216-
evaluator = self._get_evaluator({}, has_mentions=True, user_mentions=set())
217-
self.assertFalse(evaluator.matches(condition, "@user:test", None))
218-
219-
# The Matrix ID appearing anywhere in the mentions list should match
220-
evaluator = self._get_evaluator(
221-
{}, has_mentions=True, user_mentions={"@user:test"}
222-
)
223-
self.assertTrue(evaluator.matches(condition, "@user:test", None))
224-
225-
evaluator = self._get_evaluator(
226-
{}, has_mentions=True, user_mentions={"@another:test", "@user:test"}
227-
)
228-
self.assertTrue(evaluator.matches(condition, "@user:test", None))
229-
230-
# Note that invalid data is tested at tests.push.test_bulk_push_rule_evaluator.TestBulkPushRuleEvaluator.test_mentions
231-
# since the BulkPushRuleEvaluator is what handles data sanitisation.
232-
233204
def _assert_matches(
234205
self, condition: JsonDict, content: JsonMapping, msg: Optional[str] = None
235206
) -> None:

0 commit comments

Comments
 (0)