Skip to content

Commit

Permalink
message send: Introduce dataclass to wrap user-notifications variables.
Browse files Browse the repository at this point in the history
We will in later commits, extend this class to contain methods
to determine if a message is notifiable or not, but for now
we only turn it into a dict and pass it on.
  • Loading branch information
abhijeetbodas2001 authored and timabbott committed Jun 15, 2021
1 parent 2179275 commit 951b49c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
21 changes: 12 additions & 9 deletions zerver/lib/actions.py
Expand Up @@ -110,6 +110,7 @@
update_first_visible_message_id,
wildcard_mention_allowed,
)
from zerver.lib.notification_data import UserMessageNotificationsData
from zerver.lib.pysa import mark_sanitized
from zerver.lib.queue import queue_json_publish
from zerver.lib.realm_icon import realm_icon_url
Expand Down Expand Up @@ -1979,15 +1980,17 @@ def do_send_messages(
user_id in send_request.wildcard_mention_user_ids and "wildcard_mentioned" in flags
)
users.append(
dict(
id=user_id,
flags=flags,
mentioned=("mentioned" in flags),
online_push_enabled=(user_id in send_request.online_push_user_ids),
stream_push_notify=(user_id in send_request.stream_push_user_ids),
stream_email_notify=(user_id in send_request.stream_email_user_ids),
wildcard_mention_notify=wildcard_mention_notify,
sender_is_muted=(user_id in send_request.muted_sender_user_ids),
asdict(
UserMessageNotificationsData(
id=user_id,
flags=flags,
mentioned=("mentioned" in flags),
online_push_enabled=(user_id in send_request.online_push_user_ids),
stream_push_notify=(user_id in send_request.stream_push_user_ids),
stream_email_notify=(user_id in send_request.stream_email_user_ids),
wildcard_mention_notify=wildcard_mention_notify,
sender_is_muted=(user_id in send_request.muted_sender_user_ids),
)
)
)

Expand Down
20 changes: 20 additions & 0 deletions zerver/lib/notification_data.py
@@ -0,0 +1,20 @@
from dataclasses import dataclass
from typing import List


@dataclass
class UserMessageNotificationsData:
id: int
flags: List[str]
mentioned: bool
online_push_enabled: bool
stream_push_notify: bool
stream_email_notify: bool
wildcard_mention_notify: bool
sender_is_muted: bool

def __post_init__(self) -> None:
if self.mentioned:
assert "mentioned" in self.flags
if self.wildcard_mention_notify:
assert "wildcard_mentioned" in self.flags

0 comments on commit 951b49c

Please sign in to comment.