From 217927502035cef8d7f656a6a8df3981dffbd4b7 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Bodas Date: Thu, 10 Jun 2021 20:32:12 +0530 Subject: [PATCH] event_queue: Deduplicate `mentioned` flag calculation. This gives us a single place where all user data for the message send event is calculated, and is a prep change for introducing a TypedDict or dataclass to keep this data toghether. --- zerver/lib/actions.py | 1 + zerver/tornado/event_queue.py | 8 +++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index feb837cdbd..644e1898a9 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -1982,6 +1982,7 @@ def do_send_messages( 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), diff --git a/zerver/tornado/event_queue.py b/zerver/tornado/event_queue.py index 89de868c57..d5ac1f607f 100644 --- a/zerver/tornado/event_queue.py +++ b/zerver/tornado/event_queue.py @@ -733,7 +733,6 @@ def missedmessage_hook( for event in client.event_queue.contents(include_internal_data=True): if event["type"] != "message": continue - internal_data = event.get("internal_data", {}) sender_is_muted = internal_data.get("sender_is_muted", False) @@ -742,9 +741,7 @@ def missedmessage_hook( assert "flags" in event - flags = event["flags"] - - mentioned = "mentioned" in flags + mentioned = internal_data.get("mentioned", False) private_message = event["message"]["type"] == "private" # stream_push_notify is set in process_message_event. stream_push_notify = internal_data.get("stream_push_notify", False) @@ -949,7 +946,7 @@ def process_message_event( # If the recipient was offline and the message was a single or group PM to them # or they were @-notified potentially notify more immediately private_message = message_type == "private" and user_profile_id != sender_id - mentioned = "mentioned" in flags + mentioned = user_data.get("mentioned", False) stream_push_notify = user_data.get("stream_push_notify", False) stream_email_notify = user_data.get("stream_email_notify", False) wildcard_mention_notify = user_data.get("wildcard_mention_notify", False) @@ -957,6 +954,7 @@ def process_message_event( extra_user_data[user_profile_id] = dict( internal_data=dict( + mentioned=mentioned, stream_push_notify=stream_push_notify, stream_email_notify=stream_email_notify, wildcard_mention_notify=wildcard_mention_notify,