Skip to content

Commit

Permalink
Count as unread by users everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
bradtgmurray committed Feb 11, 2022
1 parent 5a01db9 commit fe076b1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
7 changes: 4 additions & 3 deletions synapse/push/bulk_push_rule_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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,
)


Expand Down
5 changes: 2 additions & 3 deletions synapse/storage/databases/main/event_push_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

logger = logging.getLogger(__name__)


DEFAULT_NOTIF_ACTION: List[Union[dict, str]] = [
"notify",
{"set_tweak": "highlight", "value": False},
Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/replication/slave/storage/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tests/storage/test_event_push_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit fe076b1

Please sign in to comment.