mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 17:07:07 +00:00
message: Extract build_message_send_dict function.
We extract the loop for building message dict in do_send_messages in a separate function named build_message_send_dict. This is a prep commit for moving the code for building of message dict in check_message.
This commit is contained in:
@@ -1386,28 +1386,8 @@ def do_schedule_messages(messages: Sequence[Mapping[str, Any]]) -> List[int]:
|
||||
return [scheduled_message.id for scheduled_message in scheduled_messages]
|
||||
|
||||
|
||||
def do_send_messages(messages_maybe_none: Sequence[Optional[MutableMapping[str, Any]]],
|
||||
email_gateway: bool=False,
|
||||
mark_as_read: Sequence[int]=[]) -> List[int]:
|
||||
"""See
|
||||
https://zulip.readthedocs.io/en/latest/subsystems/sending-messages.html
|
||||
for high-level documentation on this subsystem.
|
||||
"""
|
||||
|
||||
# Filter out messages which didn't pass internal_prep_message properly
|
||||
messages = [message for message in messages_maybe_none if message is not None]
|
||||
|
||||
# Filter out zephyr mirror anomalies where the message was already sent
|
||||
already_sent_ids: List[int] = []
|
||||
new_messages: List[MutableMapping[str, Any]] = []
|
||||
for message in messages:
|
||||
if isinstance(message['message'], int):
|
||||
already_sent_ids.append(message['message'])
|
||||
else:
|
||||
new_messages.append(message)
|
||||
messages = new_messages
|
||||
|
||||
for message_dict in messages:
|
||||
def build_message_send_dict(message_dict: MutableMapping[str, Any],
|
||||
email_gateway: bool=False) -> MutableMapping[str, Any]:
|
||||
message_dict['stream'] = message_dict.get('stream', None)
|
||||
message_dict['local_id'] = message_dict.get('local_id', None)
|
||||
message_dict['sender_queue_id'] = message_dict.get('sender_queue_id', None)
|
||||
@@ -1485,6 +1465,32 @@ def do_send_messages(messages_maybe_none: Sequence[Optional[MutableMapping[str,
|
||||
mentioned_bot_user_ids = default_bot_user_ids & mentioned_user_ids
|
||||
message_dict['um_eligible_user_ids'] |= mentioned_bot_user_ids
|
||||
|
||||
return message_dict
|
||||
|
||||
def do_send_messages(messages_maybe_none: Sequence[Optional[MutableMapping[str, Any]]],
|
||||
email_gateway: bool=False,
|
||||
mark_as_read: Sequence[int]=[]) -> List[int]:
|
||||
"""See
|
||||
https://zulip.readthedocs.io/en/latest/subsystems/sending-messages.html
|
||||
for high-level documentation on this subsystem.
|
||||
"""
|
||||
|
||||
# Filter out messages which didn't pass internal_prep_message properly
|
||||
messages = [message for message in messages_maybe_none if message is not None]
|
||||
|
||||
# Filter out zephyr mirror anomalies where the message was already sent
|
||||
already_sent_ids: List[int] = []
|
||||
new_messages: List[MutableMapping[str, Any]] = []
|
||||
for message in messages:
|
||||
if isinstance(message['message'], int):
|
||||
already_sent_ids.append(message['message'])
|
||||
else:
|
||||
new_messages.append(message)
|
||||
messages = new_messages
|
||||
|
||||
for message_dict in messages:
|
||||
message_dict = build_message_send_dict(message_dict, email_gateway)
|
||||
|
||||
# Save the message receipts in the database
|
||||
user_message_flags: Dict[int, Dict[int, List[str]]] = defaultdict(dict)
|
||||
with transaction.atomic():
|
||||
|
||||
Reference in New Issue
Block a user