email_notifications: Make stream_id_map optional to build_message_list.

This feels cleaner than passing an empty dict.
This commit is contained in:
Alex Vandiver 2023-08-31 17:54:02 +00:00 committed by Tim Abbott
parent f8a9779b54
commit ffb6c95bba
1 changed files with 4 additions and 4 deletions

View File

@ -195,7 +195,7 @@ def add_quote_prefix_in_text(content: str) -> str:
def build_message_list( def build_message_list(
user: UserProfile, user: UserProfile,
messages: List[Message], messages: List[Message],
stream_id_map: Dict[int, Stream], # only needs id, name stream_id_map: Optional[Dict[int, Stream]] = None, # only needs id, name
) -> List[Dict[str, Any]]: ) -> List[Dict[str, Any]]:
""" """
Builds the message list object for the message notification email template. Builds the message list object for the message notification email template.
@ -280,8 +280,9 @@ def build_message_list(
assert message.recipient.type == Recipient.STREAM assert message.recipient.type == Recipient.STREAM
grouping = {"stream": message.recipient_id, "topic": message.topic_name().lower()} grouping = {"stream": message.recipient_id, "topic": message.topic_name().lower()}
stream_id = message.recipient.type_id stream_id = message.recipient.type_id
stream = stream_id_map.get(stream_id, None) if stream_id_map is not None and stream_id in stream_id_map:
if stream is None: stream = stream_id_map[stream_id]
else:
# Some of our callers don't populate stream_map, so # Some of our callers don't populate stream_map, so
# we just populate the stream from the database. # we just populate the stream from the database.
stream = Stream.objects.only("id", "name").get(id=stream_id) stream = Stream.objects.only("id", "name").get(id=stream_id)
@ -558,7 +559,6 @@ def do_send_missedmessage_events_reply_in_zulip(
messages=build_message_list( messages=build_message_list(
user=user_profile, user=user_profile,
messages=[m["message"] for m in missed_messages], messages=[m["message"] for m in missed_messages],
stream_map={},
), ),
sender_str=", ".join(sender.full_name for sender in senders), sender_str=", ".join(sender.full_name for sender in senders),
realm_str=user_profile.realm.name, realm_str=user_profile.realm.name,