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

Only notify the target of a membership event #14971

Merged
merged 3 commits into from
Feb 6, 2023
Merged
Changes from 1 commit
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
13 changes: 11 additions & 2 deletions synapse/push/bulk_push_rule_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,17 @@ async def _get_rules_for_event(
# little, we can skip fetching a huge number of push rules in large rooms.
# This helps make joins and leaves faster.
if event.type == EventTypes.Member:
if self.hs.is_mine_id(event.state_key):
local_users = [event.state_key]
# We never notify a user about their own actions. This is enforced in
# `_action_for_event_by_user` in the loop over `rules_by_user`, but we
# do the same check here to avoid unnecessary DB queries.
if event.sender != event.state_key and self.hs.is_mine_id(event.state_key):
# Check the target is in the room, to avoid notifying them of
# e.g. a pre-emptive ban.
target_already_in_room = await self.store.check_local_user_in_room(
event.state_key, event.room_id
)
if target_already_in_room:
local_users = [event.state_key]
Comment on lines +158 to +159
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not target_already_in_room then we don't give local_users a value 🤦.

We were surprised that the linting didn't spot this. I opened astral-sh/ruff#2493 to see what the ruff author(s?) think.

else:
return {}
else:
Expand Down