diff --git a/synapse/push/bulk_push_rule_evaluator.py b/synapse/push/bulk_push_rule_evaluator.py index f4d1f16b9275..ec770c9c6b8f 100644 --- a/synapse/push/bulk_push_rule_evaluator.py +++ b/synapse/push/bulk_push_rule_evaluator.py @@ -186,6 +186,7 @@ async def action_for_event_by_user( """ rules_by_user = await self._get_rules_for_event(event, context) actions_by_user: Dict[str, List[Union[dict, str]]] = {} + count_as_unread_by_user: Dict[str, bool] = {} room_members = await self.store.get_joined_users_from_context(event, context) @@ -237,9 +238,9 @@ async def action_for_event_by_user( # Beeper: Need to calculate this per user as whether it should count as unread or not depends on who the # current user is - count_as_unread = _should_count_as_unread(event, context, room_members, uid, related_event) + count_as_unread_by_user[uid] = _should_count_as_unread(event, context, room_members, uid, related_event) - if count_as_unread: + if count_as_unread_by_user[uid]: # Add an element for the current user if the event needs to be marked as # unread, so that add_push_actions_to_staging iterates over it. # If the event shouldn't be marked as unread but should notify the @@ -266,7 +267,7 @@ async def action_for_event_by_user( await self.store.add_push_actions_to_staging( event.event_id, actions_by_user, - count_as_unread, + count_as_unread_by_user, ) diff --git a/synapse/storage/databases/main/event_push_actions.py b/synapse/storage/databases/main/event_push_actions.py index b7c4c62222bd..2d1b8b11f355 100644 --- a/synapse/storage/databases/main/event_push_actions.py +++ b/synapse/storage/databases/main/event_push_actions.py @@ -32,7 +32,6 @@ logger = logging.getLogger(__name__) - DEFAULT_NOTIF_ACTION: List[Union[dict, str]] = [ "notify", {"set_tweak": "highlight", "value": False}, @@ -527,7 +526,7 @@ async def add_push_actions_to_staging( self, event_id: str, user_id_actions: Dict[str, List[Union[dict, str]]], - count_as_unread: bool, + count_as_unread_by_user: Dict[str, bool], ) -> None: """Add the push actions for the event to the push action staging area. @@ -553,7 +552,7 @@ def _gen_entry( _serialize_action(actions, bool(is_highlight)), # actions column notif, # notif column is_highlight, # highlight column - int(count_as_unread), # unread column + int(count_as_unread_by_user[user_id]), # unread column ) def _add_push_actions_to_staging_txn(txn: LoggingTransaction) -> None: diff --git a/tests/replication/slave/storage/test_events.py b/tests/replication/slave/storage/test_events.py index eca6a443af78..1f4e09c02b6f 100644 --- a/tests/replication/slave/storage/test_events.py +++ b/tests/replication/slave/storage/test_events.py @@ -388,7 +388,7 @@ def build_event( self.master_store.add_push_actions_to_staging( event.event_id, {user_id: actions for user_id, actions in push_actions}, - False, + {user_id: False for user_id, _ in push_actions}, ) ) return event, context diff --git a/tests/storage/test_event_push_actions.py b/tests/storage/test_event_push_actions.py index 738f3ad1dcc7..5e02d2c7f09e 100644 --- a/tests/storage/test_event_push_actions.py +++ b/tests/storage/test_event_push_actions.py @@ -78,7 +78,7 @@ def _inject_actions(stream, action): self.store.add_push_actions_to_staging( event.event_id, {user_id: action}, - False, + {user_id: False}, ) ) self.get_success(