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

Commit

Permalink
Remove unneeded parameters on objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed Oct 7, 2022
1 parent 5958961 commit 979a513
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 41 deletions.
24 changes: 3 additions & 21 deletions rust/src/push/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::collections::{BTreeMap, BTreeSet};
use std::collections::BTreeMap;

use anyhow::{Context, Error};
use lazy_static::lazy_static;
Expand Down Expand Up @@ -46,13 +46,6 @@ pub struct PushRuleEvaluator {
/// The `notifications` section of the current power levels in the room.
notification_power_levels: BTreeMap<String, i64>,

/// The relations related to the event as a mapping from relation type to
/// set of sender/event type 2-tuples.
relations: BTreeMap<String, BTreeSet<(String, String)>>,

/// Is running "relation" conditions enabled?
relation_match_enabled: bool,

/// The power level of the sender of the event, or None if event is an
/// outlier.
sender_power_level: Option<i64>,
Expand All @@ -67,8 +60,6 @@ impl PushRuleEvaluator {
room_member_count: u64,
sender_power_level: Option<i64>,
notification_power_levels: BTreeMap<String, i64>,
relations: BTreeMap<String, BTreeSet<(String, String)>>,
relation_match_enabled: bool,
) -> Result<Self, Error> {
let body = flattened_keys
.get("content.body")
Expand All @@ -80,8 +71,6 @@ impl PushRuleEvaluator {
body,
room_member_count,
notification_power_levels,
relations,
relation_match_enabled,
sender_power_level,
})
}
Expand Down Expand Up @@ -278,15 +267,8 @@ impl PushRuleEvaluator {
fn push_rule_evaluator() {
let mut flattened_keys = BTreeMap::new();
flattened_keys.insert("content.body".to_string(), "foo bar bob hello".to_string());
let evaluator = PushRuleEvaluator::py_new(
flattened_keys,
10,
Some(0),
BTreeMap::new(),
BTreeMap::new(),
true,
)
.unwrap();
let evaluator =
PushRuleEvaluator::py_new(flattened_keys, 10, Some(0), BTreeMap::new()).unwrap();

let result = evaluator.run(&FilteredPushRules::default(), None, Some("bob"));
assert_eq!(result.len(), 3);
Expand Down
2 changes: 0 additions & 2 deletions stubs/synapse/synapse_rust/push.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ class PushRuleEvaluator:
room_member_count: int,
sender_power_level: Optional[int],
notification_power_levels: Mapping[str, int],
relations: Mapping[str, Set[Tuple[str, str]]],
relation_match_enabled: bool,
): ...
def run(
self,
Expand Down
11 changes: 2 additions & 9 deletions synapse/push/bulk_push_rule_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,11 @@ async def action_for_event_by_user(
sender_power_level,
) = await self._get_power_levels_and_sender_level(event, context)

# Find the event's thread ID.
relation = relation_from_event(event)
# If the event does not have a relation, then cannot have any mutual
# relations or thread ID.
relations = {}
# If the event does not have a relation, then it cannot have a thread ID.
thread_id = MAIN_TIMELINE
if relation:
relations = await self._get_mutual_relations(
relation.parent_id,
itertools.chain(*(r.rules() for r in rules_by_user.values())),
)
# Recursively attempt to find the thread this event relates to.
if relation.rel_type == RelationTypes.THREAD:
thread_id = relation.parent_id
Expand All @@ -306,8 +301,6 @@ async def action_for_event_by_user(
room_member_count,
sender_power_level,
notification_levels,
relations,
self._relations_match_enabled,
)

users = rules_by_user.keys()
Expand Down
11 changes: 2 additions & 9 deletions tests/push/test_push_rule_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Dict, Optional, Set, Tuple, Union
from typing import Dict, Optional, Union

import frozendict

Expand All @@ -38,12 +38,7 @@


class PushRuleEvaluatorTestCase(unittest.TestCase):
def _get_evaluator(
self,
content: JsonDict,
relations: Optional[Dict[str, Set[Tuple[str, str]]]] = None,
relations_match_enabled: bool = False,
) -> PushRuleEvaluator:
def _get_evaluator(self, content: JsonDict) -> PushRuleEvaluator:
event = FrozenEvent(
{
"event_id": "$event_id",
Expand All @@ -63,8 +58,6 @@ def _get_evaluator(
room_member_count,
sender_power_level,
power_levels.get("notifications", {}),
relations or {},
relations_match_enabled,
)

def test_display_name(self) -> None:
Expand Down

0 comments on commit 979a513

Please sign in to comment.