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

Commit 42d261c

Browse files
authoredSep 20, 2022
Port the push rule classes to Rust. (#13768)
1 parent c802ef1 commit 42d261c

File tree

14 files changed

+930
-615
lines changed

14 files changed

+930
-615
lines changed
 

‎.rustfmt.toml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
group_imports = "StdExternalCrate"

‎changelog.d/13768.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Port push rules to using Rust.

‎rust/Cargo.toml

+9-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,15 @@ crate-type = ["cdylib"]
1818
name = "synapse.synapse_rust"
1919

2020
[dependencies]
21-
pyo3 = { version = "0.16.5", features = ["extension-module", "macros", "abi3", "abi3-py37"] }
21+
anyhow = "1.0.63"
22+
lazy_static = "1.4.0"
23+
log = "0.4.17"
24+
pyo3 = { version = "0.17.1", features = ["extension-module", "macros", "anyhow", "abi3", "abi3-py37"] }
25+
pyo3-log = "0.7.0"
26+
pythonize = "0.17.0"
27+
regex = "1.6.0"
28+
serde = { version = "1.0.144", features = ["derive"] }
29+
serde_json = "1.0.85"
2230

2331
[build-dependencies]
2432
blake2 = "0.10.4"

‎rust/src/lib.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use pyo3::prelude::*;
22

3+
pub mod push;
4+
35
/// Returns the hash of all the rust source files at the time it was compiled.
46
///
57
/// Used by python to detect if the rust library is outdated.
@@ -17,8 +19,13 @@ fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
1719

1820
/// The entry point for defining the Python module.
1921
#[pymodule]
20-
fn synapse_rust(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
22+
fn synapse_rust(py: Python<'_>, m: &PyModule) -> PyResult<()> {
23+
pyo3_log::init();
24+
2125
m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
2226
m.add_function(wrap_pyfunction!(get_rust_file_digest, m)?)?;
27+
28+
push::register_module(py, m)?;
29+
2330
Ok(())
2431
}

‎rust/src/push/base_rules.rs

+335
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,335 @@
1+
// Copyright 2022 The Matrix.org Foundation C.I.C.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//! Contains the definitions of the "base" push rules.
16+
17+
use std::borrow::Cow;
18+
use std::collections::HashMap;
19+
20+
use lazy_static::lazy_static;
21+
use serde_json::Value;
22+
23+
use super::KnownCondition;
24+
use crate::push::Action;
25+
use crate::push::Condition;
26+
use crate::push::EventMatchCondition;
27+
use crate::push::PushRule;
28+
use crate::push::SetTweak;
29+
use crate::push::TweakValue;
30+
31+
const HIGHLIGHT_ACTION: Action = Action::SetTweak(SetTweak {
32+
set_tweak: Cow::Borrowed("highlight"),
33+
value: None,
34+
other_keys: Value::Null,
35+
});
36+
37+
const HIGHLIGHT_FALSE_ACTION: Action = Action::SetTweak(SetTweak {
38+
set_tweak: Cow::Borrowed("highlight"),
39+
value: Some(TweakValue::Other(Value::Bool(false))),
40+
other_keys: Value::Null,
41+
});
42+
43+
const SOUND_ACTION: Action = Action::SetTweak(SetTweak {
44+
set_tweak: Cow::Borrowed("sound"),
45+
value: Some(TweakValue::String(Cow::Borrowed("default"))),
46+
other_keys: Value::Null,
47+
});
48+
49+
const RING_ACTION: Action = Action::SetTweak(SetTweak {
50+
set_tweak: Cow::Borrowed("sound"),
51+
value: Some(TweakValue::String(Cow::Borrowed("ring"))),
52+
other_keys: Value::Null,
53+
});
54+
55+
pub const BASE_PREPEND_OVERRIDE_RULES: &[PushRule] = &[PushRule {
56+
rule_id: Cow::Borrowed("global/override/.m.rule.master"),
57+
priority_class: 5,
58+
conditions: Cow::Borrowed(&[]),
59+
actions: Cow::Borrowed(&[Action::DontNotify]),
60+
default: true,
61+
default_enabled: false,
62+
}];
63+
64+
pub const BASE_APPEND_OVERRIDE_RULES: &[PushRule] = &[
65+
PushRule {
66+
rule_id: Cow::Borrowed("global/override/.m.rule.suppress_notices"),
67+
priority_class: 5,
68+
conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
69+
EventMatchCondition {
70+
key: Cow::Borrowed("content.msgtype"),
71+
pattern: Some(Cow::Borrowed("m.notice")),
72+
pattern_type: None,
73+
},
74+
))]),
75+
actions: Cow::Borrowed(&[Action::DontNotify]),
76+
default: true,
77+
default_enabled: true,
78+
},
79+
PushRule {
80+
rule_id: Cow::Borrowed("global/override/.m.rule.invite_for_me"),
81+
priority_class: 5,
82+
conditions: Cow::Borrowed(&[
83+
Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
84+
key: Cow::Borrowed("type"),
85+
pattern: Some(Cow::Borrowed("m.room.member")),
86+
pattern_type: None,
87+
})),
88+
Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
89+
key: Cow::Borrowed("content.membership"),
90+
pattern: Some(Cow::Borrowed("invite")),
91+
pattern_type: None,
92+
})),
93+
Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
94+
key: Cow::Borrowed("state_key"),
95+
pattern: None,
96+
pattern_type: Some(Cow::Borrowed("user_id")),
97+
})),
98+
]),
99+
actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION, SOUND_ACTION]),
100+
default: true,
101+
default_enabled: true,
102+
},
103+
PushRule {
104+
rule_id: Cow::Borrowed("global/override/.m.rule.member_event"),
105+
priority_class: 5,
106+
conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
107+
EventMatchCondition {
108+
key: Cow::Borrowed("type"),
109+
pattern: Some(Cow::Borrowed("m.room.member")),
110+
pattern_type: None,
111+
},
112+
))]),
113+
actions: Cow::Borrowed(&[Action::DontNotify]),
114+
default: true,
115+
default_enabled: true,
116+
},
117+
PushRule {
118+
rule_id: Cow::Borrowed("global/override/.m.rule.contains_display_name"),
119+
priority_class: 5,
120+
conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::ContainsDisplayName)]),
121+
actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_ACTION, SOUND_ACTION]),
122+
default: true,
123+
default_enabled: true,
124+
},
125+
PushRule {
126+
rule_id: Cow::Borrowed("global/override/.m.rule.roomnotif"),
127+
priority_class: 5,
128+
conditions: Cow::Borrowed(&[
129+
Condition::Known(KnownCondition::SenderNotificationPermission {
130+
key: Cow::Borrowed("room"),
131+
}),
132+
Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
133+
key: Cow::Borrowed("content.body"),
134+
pattern: Some(Cow::Borrowed("@room")),
135+
pattern_type: None,
136+
})),
137+
]),
138+
actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_ACTION]),
139+
default: true,
140+
default_enabled: true,
141+
},
142+
PushRule {
143+
rule_id: Cow::Borrowed("global/override/.m.rule.tombstone"),
144+
priority_class: 5,
145+
conditions: Cow::Borrowed(&[
146+
Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
147+
key: Cow::Borrowed("type"),
148+
pattern: Some(Cow::Borrowed("m.room.tombstone")),
149+
pattern_type: None,
150+
})),
151+
Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
152+
key: Cow::Borrowed("state_key"),
153+
pattern: Some(Cow::Borrowed("")),
154+
pattern_type: None,
155+
})),
156+
]),
157+
actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_ACTION]),
158+
default: true,
159+
default_enabled: true,
160+
},
161+
PushRule {
162+
rule_id: Cow::Borrowed("global/override/.m.rule.reaction"),
163+
priority_class: 5,
164+
conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
165+
EventMatchCondition {
166+
key: Cow::Borrowed("type"),
167+
pattern: Some(Cow::Borrowed("m.reaction")),
168+
pattern_type: None,
169+
},
170+
))]),
171+
actions: Cow::Borrowed(&[Action::DontNotify]),
172+
default: true,
173+
default_enabled: true,
174+
},
175+
PushRule {
176+
rule_id: Cow::Borrowed("global/override/.org.matrix.msc3786.rule.room.server_acl"),
177+
priority_class: 5,
178+
conditions: Cow::Borrowed(&[
179+
Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
180+
key: Cow::Borrowed("type"),
181+
pattern: Some(Cow::Borrowed("m.room.server_acl")),
182+
pattern_type: None,
183+
})),
184+
Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
185+
key: Cow::Borrowed("state_key"),
186+
pattern: Some(Cow::Borrowed("")),
187+
pattern_type: None,
188+
})),
189+
]),
190+
actions: Cow::Borrowed(&[]),
191+
default: true,
192+
default_enabled: true,
193+
},
194+
];
195+
196+
pub const BASE_APPEND_CONTENT_RULES: &[PushRule] = &[PushRule {
197+
rule_id: Cow::Borrowed("global/content/.m.rule.contains_user_name"),
198+
priority_class: 4,
199+
conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
200+
EventMatchCondition {
201+
key: Cow::Borrowed("content.body"),
202+
pattern: None,
203+
pattern_type: Some(Cow::Borrowed("user_localpart")),
204+
},
205+
))]),
206+
actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_ACTION, SOUND_ACTION]),
207+
default: true,
208+
default_enabled: true,
209+
}];
210+
211+
pub const BASE_APPEND_UNDERRIDE_RULES: &[PushRule] = &[
212+
PushRule {
213+
rule_id: Cow::Borrowed("global/underride/.m.rule.call"),
214+
priority_class: 1,
215+
conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
216+
EventMatchCondition {
217+
key: Cow::Borrowed("type"),
218+
pattern: Some(Cow::Borrowed("m.call.invite")),
219+
pattern_type: None,
220+
},
221+
))]),
222+
actions: Cow::Borrowed(&[Action::Notify, RING_ACTION, HIGHLIGHT_FALSE_ACTION]),
223+
default: true,
224+
default_enabled: true,
225+
},
226+
PushRule {
227+
rule_id: Cow::Borrowed("global/underride/.m.rule.room_one_to_one"),
228+
priority_class: 1,
229+
conditions: Cow::Borrowed(&[
230+
Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
231+
key: Cow::Borrowed("type"),
232+
pattern: Some(Cow::Borrowed("m.room.message")),
233+
pattern_type: None,
234+
})),
235+
Condition::Known(KnownCondition::RoomMemberCount {
236+
is: Some(Cow::Borrowed("2")),
237+
}),
238+
]),
239+
actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION, HIGHLIGHT_FALSE_ACTION]),
240+
default: true,
241+
default_enabled: true,
242+
},
243+
PushRule {
244+
rule_id: Cow::Borrowed("global/underride/.m.rule.encrypted_room_one_to_one"),
245+
priority_class: 1,
246+
conditions: Cow::Borrowed(&[
247+
Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
248+
key: Cow::Borrowed("type"),
249+
pattern: Some(Cow::Borrowed("m.room.encrypted")),
250+
pattern_type: None,
251+
})),
252+
Condition::Known(KnownCondition::RoomMemberCount {
253+
is: Some(Cow::Borrowed("2")),
254+
}),
255+
]),
256+
actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION, HIGHLIGHT_FALSE_ACTION]),
257+
default: true,
258+
default_enabled: true,
259+
},
260+
PushRule {
261+
rule_id: Cow::Borrowed("global/underride/.org.matrix.msc3772.thread_reply"),
262+
priority_class: 1,
263+
conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::RelationMatch {
264+
rel_type: Cow::Borrowed("m.thread"),
265+
sender: None,
266+
sender_type: Some(Cow::Borrowed("user_id")),
267+
})]),
268+
actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
269+
default: true,
270+
default_enabled: true,
271+
},
272+
PushRule {
273+
rule_id: Cow::Borrowed("global/underride/.m.rule.message"),
274+
priority_class: 1,
275+
conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
276+
EventMatchCondition {
277+
key: Cow::Borrowed("type"),
278+
pattern: Some(Cow::Borrowed("m.room.message")),
279+
pattern_type: None,
280+
},
281+
))]),
282+
actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
283+
default: true,
284+
default_enabled: true,
285+
},
286+
PushRule {
287+
rule_id: Cow::Borrowed("global/underride/.m.rule.encrypted"),
288+
priority_class: 1,
289+
conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
290+
EventMatchCondition {
291+
key: Cow::Borrowed("type"),
292+
pattern: Some(Cow::Borrowed("m.room.encrypted")),
293+
pattern_type: None,
294+
},
295+
))]),
296+
actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
297+
default: true,
298+
default_enabled: true,
299+
},
300+
PushRule {
301+
rule_id: Cow::Borrowed("global/underride/.im.vector.jitsi"),
302+
priority_class: 1,
303+
conditions: Cow::Borrowed(&[
304+
Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
305+
key: Cow::Borrowed("type"),
306+
pattern: Some(Cow::Borrowed("im.vector.modular.widgets")),
307+
pattern_type: None,
308+
})),
309+
Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
310+
key: Cow::Borrowed("content.type"),
311+
pattern: Some(Cow::Borrowed("jitsi")),
312+
pattern_type: None,
313+
})),
314+
Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
315+
key: Cow::Borrowed("state_key"),
316+
pattern: Some(Cow::Borrowed("*")),
317+
pattern_type: None,
318+
})),
319+
]),
320+
actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
321+
default: true,
322+
default_enabled: true,
323+
},
324+
];
325+
326+
lazy_static! {
327+
pub static ref BASE_RULES_BY_ID: HashMap<&'static str, &'static PushRule> =
328+
BASE_PREPEND_OVERRIDE_RULES
329+
.iter()
330+
.chain(BASE_APPEND_OVERRIDE_RULES.iter())
331+
.chain(BASE_APPEND_CONTENT_RULES.iter())
332+
.chain(BASE_APPEND_UNDERRIDE_RULES.iter())
333+
.map(|rule| { (&*rule.rule_id, rule) })
334+
.collect();
335+
}

‎rust/src/push/mod.rs

+502
Large diffs are not rendered by default.
File renamed without changes.

‎stubs/synapse/synapse_rust/push.pyi

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from typing import Any, Collection, Dict, Mapping, Sequence, Tuple, Union
2+
3+
from synapse.types import JsonDict
4+
5+
class PushRule:
6+
@property
7+
def rule_id(self) -> str: ...
8+
@property
9+
def priority_class(self) -> int: ...
10+
@property
11+
def conditions(self) -> Sequence[Mapping[str, str]]: ...
12+
@property
13+
def actions(self) -> Sequence[Union[Mapping[str, Any], str]]: ...
14+
@property
15+
def default(self) -> bool: ...
16+
@property
17+
def default_enabled(self) -> bool: ...
18+
@staticmethod
19+
def from_db(
20+
rule_id: str, priority_class: int, conditions: str, actions: str
21+
) -> "PushRule": ...
22+
23+
class PushRules:
24+
def __init__(self, rules: Collection[PushRule]): ...
25+
def rules(self) -> Collection[PushRule]: ...
26+
27+
class FilteredPushRules:
28+
def __init__(
29+
self,
30+
push_rules: PushRules,
31+
enabled_map: Dict[str, bool],
32+
msc3786_enabled: bool,
33+
msc3772_enabled: bool,
34+
): ...
35+
def rules(self) -> Collection[Tuple[PushRule, bool]]: ...
36+
37+
def get_base_rule_ids() -> Collection[str]: ...

‎synapse/handlers/push_rules.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@
1616
import attr
1717

1818
from synapse.api.errors import SynapseError, UnrecognizedRequestError
19-
from synapse.push.baserules import BASE_RULE_IDS
2019
from synapse.storage.push_rule import RuleNotFoundException
20+
from synapse.synapse_rust.push import get_base_rule_ids
2121
from synapse.types import JsonDict
2222

2323
if TYPE_CHECKING:
2424
from synapse.server import HomeServer
2525

2626

27+
BASE_RULE_IDS = get_base_rule_ids()
28+
29+
2730
@attr.s(slots=True, frozen=True, auto_attribs=True)
2831
class RuleSpec:
2932
scope: str

‎synapse/push/baserules.py

-583
This file was deleted.

‎synapse/push/bulk_push_rule_evaluator.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@
3737
from synapse.state import POWER_KEY
3838
from synapse.storage.databases.main.roommember import EventIdMembership
3939
from synapse.storage.state import StateFilter
40+
from synapse.synapse_rust.push import FilteredPushRules, PushRule
4041
from synapse.util.caches import register_cache
4142
from synapse.util.metrics import measure_func
4243
from synapse.visibility import filter_event_for_clients_with_state
4344

44-
from .baserules import FilteredPushRules, PushRule
4545
from .push_rule_evaluator import PushRuleEvaluatorForEvent
4646

4747
if TYPE_CHECKING:
@@ -280,7 +280,8 @@ async def action_for_event_by_user(
280280
thread_id = "main"
281281
if relation:
282282
relations = await self._get_mutual_relations(
283-
relation.parent_id, itertools.chain(*rules_by_user.values())
283+
relation.parent_id,
284+
itertools.chain(*(r.rules() for r in rules_by_user.values())),
284285
)
285286
if relation.rel_type == RelationTypes.THREAD:
286287
thread_id = relation.parent_id
@@ -333,7 +334,7 @@ async def action_for_event_by_user(
333334
# current user, it'll be added to the dict later.
334335
actions_by_user[uid] = []
335336

336-
for rule, enabled in rules:
337+
for rule, enabled in rules.rules():
337338
if not enabled:
338339
continue
339340

‎synapse/push/clientformat.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
from typing import Any, Dict, List, Optional
1717

1818
from synapse.push.rulekinds import PRIORITY_CLASS_INVERSE_MAP, PRIORITY_CLASS_MAP
19+
from synapse.synapse_rust.push import FilteredPushRules, PushRule
1920
from synapse.types import UserID
2021

21-
from .baserules import FilteredPushRules, PushRule
22-
2322

2423
def format_push_rules_for_user(
2524
user: UserID, ruleslist: FilteredPushRules
@@ -34,7 +33,7 @@ def format_push_rules_for_user(
3433

3534
rules["global"] = _add_empty_priority_class_arrays(rules["global"])
3635

37-
for r, enabled in ruleslist:
36+
for r, enabled in ruleslist.rules():
3837
template_name = _priority_class_to_template_name(r.priority_class)
3938

4039
rulearray = rules["global"][template_name]

‎synapse/storage/databases/main/push_rule.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@
3030

3131
from synapse.api.errors import StoreError
3232
from synapse.config.homeserver import ExperimentalConfig
33-
from synapse.push.baserules import FilteredPushRules, PushRule, compile_push_rules
3433
from synapse.replication.slave.storage._slaved_id_tracker import SlavedIdTracker
35-
from synapse.storage._base import SQLBaseStore, db_to_json
34+
from synapse.storage._base import SQLBaseStore
3635
from synapse.storage.database import (
3736
DatabasePool,
3837
LoggingDatabaseConnection,
@@ -51,6 +50,7 @@
5150
IdGenerator,
5251
StreamIdGenerator,
5352
)
53+
from synapse.synapse_rust.push import FilteredPushRules, PushRule, PushRules
5454
from synapse.types import JsonDict
5555
from synapse.util import json_encoder
5656
from synapse.util.caches.descriptors import cached, cachedList
@@ -72,18 +72,25 @@ def _load_rules(
7272
"""
7373

7474
ruleslist = [
75-
PushRule(
75+
PushRule.from_db(
7676
rule_id=rawrule["rule_id"],
7777
priority_class=rawrule["priority_class"],
78-
conditions=db_to_json(rawrule["conditions"]),
79-
actions=db_to_json(rawrule["actions"]),
78+
conditions=rawrule["conditions"],
79+
actions=rawrule["actions"],
8080
)
8181
for rawrule in rawrules
8282
]
8383

84-
push_rules = compile_push_rules(ruleslist)
84+
push_rules = PushRules(
85+
ruleslist,
86+
)
8587

86-
filtered_rules = FilteredPushRules(push_rules, enabled_map, experimental_config)
88+
filtered_rules = FilteredPushRules(
89+
push_rules,
90+
enabled_map,
91+
msc3786_enabled=experimental_config.msc3786_enabled,
92+
msc3772_enabled=experimental_config.msc3772_enabled,
93+
)
8794

8895
return filtered_rules
8996

@@ -845,7 +852,7 @@ async def copy_push_rules_from_room_to_room_for_user(
845852
user_push_rules = await self.get_push_rules_for_user(user_id)
846853

847854
# Get rules relating to the old room and copy them to the new room
848-
for rule, enabled in user_push_rules:
855+
for rule, enabled in user_push_rules.rules():
849856
if not enabled:
850857
continue
851858

‎tests/handlers/test_deactivate_account.py

+12-15
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
from twisted.test.proto_helpers import MemoryReactor
1616

1717
from synapse.api.constants import AccountDataTypes
18-
from synapse.push.baserules import PushRule
1918
from synapse.push.rulekinds import PRIORITY_CLASS_MAP
2019
from synapse.rest import admin
2120
from synapse.rest.client import account, login
2221
from synapse.server import HomeServer
22+
from synapse.synapse_rust.push import PushRule
2323
from synapse.util import Clock
2424

2525
from tests.unittest import HomeserverTestCase
@@ -161,20 +161,15 @@ def test_push_rules_deleted_upon_account_deactivation(self) -> None:
161161
self._store.get_push_rules_for_user(self.user)
162162
)
163163
# Filter out default rules; we don't care
164-
push_rules = [r for r, _ in filtered_push_rules if self._is_custom_rule(r)]
164+
push_rules = [
165+
r for r, _ in filtered_push_rules.rules() if self._is_custom_rule(r)
166+
]
165167
# Check our rule made it
166-
self.assertEqual(
167-
push_rules,
168-
[
169-
PushRule(
170-
rule_id="personal.override.rule1",
171-
priority_class=5,
172-
conditions=[],
173-
actions=[],
174-
)
175-
],
176-
push_rules,
177-
)
168+
self.assertEqual(len(push_rules), 1)
169+
self.assertEqual(push_rules[0].rule_id, "personal.override.rule1")
170+
self.assertEqual(push_rules[0].priority_class, 5)
171+
self.assertEqual(push_rules[0].conditions, [])
172+
self.assertEqual(push_rules[0].actions, [])
178173

179174
# Request the deactivation of our account
180175
self._deactivate_my_account()
@@ -183,7 +178,9 @@ def test_push_rules_deleted_upon_account_deactivation(self) -> None:
183178
self._store.get_push_rules_for_user(self.user)
184179
)
185180
# Filter out default rules; we don't care
186-
push_rules = [r for r, _ in filtered_push_rules if self._is_custom_rule(r)]
181+
push_rules = [
182+
r for r, _ in filtered_push_rules.rules() if self._is_custom_rule(r)
183+
]
187184
# Check our rule no longer exists
188185
self.assertEqual(push_rules, [], push_rules)
189186

0 commit comments

Comments
 (0)
This repository has been archived.