Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
actions: Refactor check_message to change return dataclass instead of Dict.
sahil8392fa33be68342
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.pyindex 81f5a862446..30e25e9b1f7 100644--- a/zerver/lib/actions.py+++ b/zerver/lib/actions.py@@ -13,7 +13,6 @@ from typing import (Iterable,List,Mapping,- MutableMapping,Optional,Sequence,Set,@@ -98,6 +97,7 @@ from zerver.lib.markdown import MentionData, topic_linksfrom zerver.lib.markdown import version as markdown_versionfrom zerver.lib.message import (MessageDict,+ SendMessageRequest,access_message,get_last_message_id,normalize_body,@@ -1401,23 +1401,24 @@ def get_service_bot_events(sender: UserProfile, service_bot_tuples: List[Tuple[ireturn event_dict-def do_schedule_messages(messages: Sequence[Mapping[str, Any]]) -> List[int]:+def do_schedule_messages(send_message_requests: Sequence[SendMessageRequest]) -> List[int]:scheduled_messages: List[ScheduledMessage] = []- for message in messages:+ for send_request in send_message_requests:scheduled_message = ScheduledMessage()- scheduled_message.sender = message['message'].sender- scheduled_message.recipient = message['message'].recipient- topic_name = message['message'].topic_name()+ scheduled_message.sender = send_request.message.sender+ scheduled_message.recipient = send_request.message.recipient+ topic_name = send_request.message.topic_name()scheduled_message.set_topic_name(topic_name=topic_name)- scheduled_message.content = message['message'].content- scheduled_message.sending_client = message['message'].sending_client- scheduled_message.stream = message['stream']- scheduled_message.realm = message['realm']- scheduled_message.scheduled_timestamp = message['deliver_at']- if message['delivery_type'] == 'send_later':+ scheduled_message.content = send_request.message.content+ scheduled_message.sending_client = send_request.message.sending_client+ scheduled_message.stream = send_request.stream+ scheduled_message.realm = send_request.realm+ assert send_request.deliver_at is not None+ scheduled_message.scheduled_timestamp = send_request.deliver_at+ if send_request.delivery_type == 'send_later':scheduled_message.delivery_type = ScheduledMessage.SEND_LATER- elif message['delivery_type'] == 'remind':+ elif send_request.delivery_type == 'remind':scheduled_message.delivery_type = ScheduledMessage.REMINDscheduled_messages.append(scheduled_message)@@ -1427,21 +1428,17 @@ def do_schedule_messages(messages: Sequence[Mapping[str, Any]]) -> List[int]:def build_message_send_dict(message_dict: Dict[str, Any],- email_gateway: bool=False) -> Dict[str, Any]:+ email_gateway: bool=False) -> SendMessageRequest:"""Returns a dictionary that can be passed into do_send_messages. Inproduction, this is always called by check_message, but sometesting code paths call it directly."""- 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)- message_dict['realm'] = message_dict.get('realm', message_dict['message'].sender.realm)+ realm = message_dict.get('realm', message_dict['message'].sender.realm)mention_data = MentionData(- realm_id=message_dict['realm'].id,+ realm_id=realm.id,content=message_dict['message'].content,)- message_dict['mention_data'] = mention_dataif message_dict['message'].is_stream_message():stream_id = message_dict['message'].recipient.type_id@@ -1460,33 +1457,24 @@ def build_message_send_dict(message_dict: Dict[str, Any],possible_wildcard_mention=mention_data.message_has_wildcards(),)- message_dict['active_user_ids'] = info['active_user_ids']- message_dict['push_notify_user_ids'] = info['push_notify_user_ids']- message_dict['stream_push_user_ids'] = info['stream_push_user_ids']- message_dict['stream_email_user_ids'] = info['stream_email_user_ids']- message_dict['um_eligible_user_ids'] = info['um_eligible_user_ids']- message_dict['long_term_idle_user_ids'] = info['long_term_idle_user_ids']- message_dict['default_bot_user_ids'] = info['default_bot_user_ids']- message_dict['service_bot_tuples'] = info['service_bot_tuples']-# Render our message_dicts.assert message_dict['message'].rendered_content is Nonerendered_content = render_incoming_message(message_dict['message'],message_dict['message'].content,- message_dict['active_user_ids'],- message_dict['realm'],- mention_data=message_dict['mention_data'],+ info['active_user_ids'],+ realm,+ mention_data=mention_data,email_gateway=email_gateway,)message_dict['message'].rendered_content = rendered_contentmessage_dict['message'].rendered_content_version = markdown_version- message_dict['links_for_embed'] = message_dict['message'].links_for_preview+ links_for_embed = message_dict['message'].links_for_preview# Add members of the mentioned user groups into `mentions_user_ids`.for group_id in message_dict['message'].mentions_user_group_ids:- members = message_dict['mention_data'].get_group_members(group_id)+ members = mention_data.get_group_members(group_id)message_dict['message'].mentions_user_ids.update(members)# Only send data to Tornado about wildcard mentions if message@@ -1494,9 +1482,9 @@ def build_message_send_dict(message_dict: Dict[str, Any],# mention in it (and not e.g. wildcard mention syntax inside a# code block).if message_dict['message'].mentions_wildcard:- message_dict['wildcard_mention_user_ids'] = info['wildcard_mention_user_ids']+ wildcard_mention_user_ids = info['wildcard_mention_user_ids']else:- message_dict['wildcard_mention_user_ids'] = set()+ wildcard_mention_user_ids = set()'''Once we have the actual list of mentioned ids from message@@ -1505,13 +1493,33 @@ def build_message_send_dict(message_dict: Dict[str, Any],get UserMessage rows.'''mentioned_user_ids = message_dict['message'].mentions_user_ids- default_bot_user_ids = message_dict['default_bot_user_ids']+ default_bot_user_ids = info['default_bot_user_ids']mentioned_bot_user_ids = default_bot_user_ids & mentioned_user_ids- message_dict['um_eligible_user_ids'] |= mentioned_bot_user_ids+ info['um_eligible_user_ids'] |= mentioned_bot_user_ids++ message_send_dict = SendMessageRequest(+ stream = message_dict.get('stream', None),+ local_id = message_dict.get('local_id', None),+ sender_queue_id = message_dict.get('sender_queue_id', None),+ realm=realm,+ mention_data=mention_data,+ message=message_dict['message'],+ active_user_ids = info['active_user_ids'],+ push_notify_user_ids = info['push_notify_user_ids'],+ stream_push_user_ids = info['stream_push_user_ids'],+ stream_email_user_ids = info['stream_email_user_ids'],+ um_eligible_user_ids = info['um_eligible_user_ids'],+ long_term_idle_user_ids = info['long_term_idle_user_ids'],+ default_bot_user_ids = info['default_bot_user_ids'],+ service_bot_tuples = info['service_bot_tuples'],+ wildcard_mention_user_ids=wildcard_mention_user_ids,+ links_for_embed=links_for_embed,+ widget_content=message_dict.get('widget_content', None)+ )- return message_dict+ return message_send_dict-def do_send_messages(messages_maybe_none: Sequence[Optional[MutableMapping[str, Any]]],+def do_send_messages(send_message_requests_maybe_none: Sequence[Optional[SendMessageRequest]],email_gateway: bool=False,mark_as_read: Sequence[int]=[]) -> List[int]:"""See@@ -1520,52 +1528,52 @@ def do_send_messages(messages_maybe_none: Sequence[Optional[MutableMapping[str,"""# Filter out messages which didn't pass internal_prep_message properly- messages = [message for message in messages_maybe_none if message is not None]+ send_message_requests = [send_request for send_request in send_message_requests_maybe_none if send_request is not None]# Save the message receipts in the databaseuser_message_flags: Dict[int, Dict[int, List[str]]] = defaultdict(dict)with transaction.atomic():- Message.objects.bulk_create(message['message'] for message in messages)+ Message.objects.bulk_create(send_request.message for send_request in send_message_requests)# Claim attachments in message- for message in messages:- if do_claim_attachments(message['message'],- message['message'].potential_attachment_path_ids):- message['message'].has_attachment = True- message['message'].save(update_fields=['has_attachment'])+ for send_request in send_message_requests:+ if do_claim_attachments(send_request.message,+ send_request.message.potential_attachment_path_ids):+ send_request.message.has_attachment = True+ send_request.message.save(update_fields=['has_attachment'])ums: List[UserMessageLite] = []- for message in messages:+ for send_request in send_message_requests:# Service bots (outgoing webhook bots and embedded bots) don't store UserMessage rows;# they will be processed later.- mentioned_user_ids = message['message'].mentions_user_ids+ mentioned_user_ids = send_request.message.mentions_user_idsuser_messages = create_user_messages(- message=message['message'],- um_eligible_user_ids=message['um_eligible_user_ids'],- long_term_idle_user_ids=message['long_term_idle_user_ids'],- stream_push_user_ids = message['stream_push_user_ids'],- stream_email_user_ids = message['stream_email_user_ids'],+ message=send_request.message,+ um_eligible_user_ids=send_request.um_eligible_user_ids,+ long_term_idle_user_ids=send_request.long_term_idle_user_ids,+ stream_push_user_ids = send_request.stream_push_user_ids,+ stream_email_user_ids = send_request.stream_email_user_ids,mentioned_user_ids=mentioned_user_ids,mark_as_read=mark_as_read,)for um in user_messages:- user_message_flags[message['message'].id][um.user_profile_id] = um.flags_list()+ user_message_flags[send_request.message.id][um.user_profile_id] = um.flags_list()ums.extend(user_messages)- message['message'].service_queue_events = get_service_bot_events(- sender=message['message'].sender,- service_bot_tuples=message['service_bot_tuples'],+ send_request.message.service_queue_events = get_service_bot_events(+ sender=send_request.message.sender,+ service_bot_tuples=send_request.service_bot_tuples,mentioned_user_ids=mentioned_user_ids,- active_user_ids=message['active_user_ids'],- recipient_type=message['message'].recipient.type,+ active_user_ids=send_request.active_user_ids,+ recipient_type=send_request.message.recipient.type,)bulk_insert_ums(ums)- for message in messages:- do_widget_post_save_actions(message)+ for send_request in send_message_requests:+ do_widget_post_save_actions(send_request)# This next loop is responsible for notifying other parts of the# Zulip system about the messages we just committed to the database:@@ -1574,35 +1582,35 @@ def do_send_messages(messages_maybe_none: Sequence[Optional[MutableMapping[str,# * Updating the `first_message_id` field for streams without any message history.# * Implementing the Welcome Bot reply hack# * Adding links to the embed_links queue for open graph processing.- for message in messages:+ for send_request in send_message_requests:realm_id: Optional[int] = None- if message['message'].is_stream_message():- if message['stream'] is None:- stream_id = message['message'].recipient.type_id- message['stream'] = Stream.objects.select_related().get(id=stream_id)+ if send_request.message.is_stream_message():+ if send_request.stream is None:+ stream_id = send_request.message.recipient.type_id+ send_request.stream = Stream.objects.select_related().get(id=stream_id)# assert needed because stubs for django are missing- assert message['stream'] is not None- realm_id = message['stream'].realm_id+ assert send_request.stream is not None+ realm_id = send_request.stream.realm_id# Deliver events to the real-time push system, as well as# enqueuing any additional processing triggered by the message.- wide_message_dict = MessageDict.wide_dict(message['message'], realm_id)+ wide_message_dict = MessageDict.wide_dict(send_request.message, realm_id)- user_flags = user_message_flags.get(message['message'].id, {})- sender = message['message'].sender+ user_flags = user_message_flags.get(send_request.message.id, {})+ sender = send_request.message.sendermessage_type = wide_message_dict['type']presence_idle_user_ids = get_active_presence_idle_user_ids(realm=sender.realm,sender_id=sender.id,message_type=message_type,- active_user_ids=message['active_user_ids'],+ active_user_ids=send_request.active_user_ids,user_flags=user_flags,)event = dict(type='message',- message=message['message'].id,+ message=send_request.message.id,message_dict=wide_message_dict,presence_idle_user_ids=presence_idle_user_ids,)@@ -1619,21 +1627,21 @@ def do_send_messages(messages_maybe_none: Sequence[Optional[MutableMapping[str,but we may have coverage gaps, so we should be carefulabout changing the next line.'''- user_ids = message['active_user_ids'] | set(user_flags.keys())+ user_ids = send_request.active_user_ids | set(user_flags.keys())users = [dict(id=user_id,flags=user_flags.get(user_id, []),- always_push_notify=(user_id in message['push_notify_user_ids']),- stream_push_notify=(user_id in message['stream_push_user_ids']),- stream_email_notify=(user_id in message['stream_email_user_ids']),- wildcard_mention_notify=(user_id in message['wildcard_mention_user_ids']),+ always_push_notify=(user_id in send_request.push_notify_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=(user_id in send_request.wildcard_mention_user_ids),)for user_id in user_ids]- if message['message'].is_stream_message():+ if send_request.message.is_stream_message():# Note: This is where authorization for single-stream# get_updates happens! We only attach stream data to the# notify new_message request if it's a public stream,@@ -1641,37 +1649,37 @@ def do_send_messages(messages_maybe_none: Sequence[Optional[MutableMapping[str,# messages are only associated to their subscribed users.# assert needed because stubs for django are missing- assert message['stream'] is not None- if message['stream'].is_public():- event['realm_id'] = message['stream'].realm_id- event['stream_name'] = message['stream'].name- if message['stream'].invite_only:+ assert send_request.stream is not None+ if send_request.stream.is_public():+ event['realm_id'] = send_request.stream.realm_id+ event['stream_name'] = send_request.stream.name+ if send_request.stream.invite_only:event['invite_only'] = True- if message['stream'].first_message_id is None:- message['stream'].first_message_id = message['message'].id- message['stream'].save(update_fields=["first_message_id"])- if message['local_id'] is not None:- event['local_id'] = message['local_id']- if message['sender_queue_id'] is not None:- event['sender_queue_id'] = message['sender_queue_id']- send_event(message['realm'], event, users)-- if message['links_for_embed']:+ if send_request.stream.first_message_id is None:+ send_request.stream.first_message_id = send_request.message.id+ send_request.stream.save(update_fields=["first_message_id"])+ if send_request.local_id is not None:+ event['local_id'] = send_request.local_id+ if send_request.sender_queue_id is not None:+ event['sender_queue_id'] = send_request.sender_queue_id+ send_event(send_request.realm, event, users)++ if send_request.links_for_embed:event_data = {- 'message_id': message['message'].id,- 'message_content': message['message'].content,- 'message_realm_id': message['realm'].id,- 'urls': list(message['links_for_embed'])}+ 'message_id': send_request.message.id,+ 'message_content': send_request.message.content,+ 'message_realm_id': send_request.realm.id,+ 'urls': list(send_request.links_for_embed)}queue_json_publish('embed_links', event_data)- if message['message'].recipient.type == Recipient.PERSONAL:+ if send_request.message.recipient.type == Recipient.PERSONAL:welcome_bot_id = get_system_bot(settings.WELCOME_BOT).id- if (welcome_bot_id in message['active_user_ids'] and- welcome_bot_id != message['message'].sender_id):+ if (welcome_bot_id in send_request.active_user_ids and+ welcome_bot_id != send_request.message.sender_id):from zerver.lib.onboarding import send_welcome_bot_response- send_welcome_bot_response(message)+ send_welcome_bot_response(send_request)- for queue_name, events in message['message'].service_queue_events.items():+ for queue_name, events in send_request.message.service_queue_events.items():for event in events:queue_json_publish(queue_name,@@ -1682,7 +1690,7 @@ def do_send_messages(messages_maybe_none: Sequence[Optional[MutableMapping[str,},)- return [message['message'].id for message in messages]+ return [send_request.message.id for send_request in send_message_requests]class UserMessageLite:'''@@ -2182,18 +2190,18 @@ def check_schedule_message(sender: UserProfile, client: Client,message_to,topic_name)- message = check_message(sender, client, addressee,- message_content, realm=realm,- forwarder_user_profile=forwarder_user_profile)- message['deliver_at'] = deliver_at- message['delivery_type'] = delivery_type+ send_request = check_message(sender, client, addressee,+ message_content, realm=realm,+ forwarder_user_profile=forwarder_user_profile)+ send_request.deliver_at = deliver_at+ send_request.delivery_type = delivery_type- recipient = message['message'].recipient+ recipient = send_request.message.recipientif (delivery_type == 'remind' and (recipient.type != Recipient.STREAM andrecipient.type_id != sender.id)):raise JsonableError(_("Reminders can only be set for streams."))- return do_schedule_messages([message])[0]+ return do_schedule_messages([send_request])[0]def check_default_stream_group_name(group_name: str) -> None:@@ -2326,7 +2334,7 @@ def check_message(sender: UserProfile, client: Client, addressee: Addressee,local_id: Optional[str]=None,sender_queue_id: Optional[str]=None,widget_content: Optional[str]=None,- email_gateway: bool=False) -> Dict[str, Any]:+ email_gateway: bool=False) -> SendMessageRequest:"""Seehttps://zulip.readthedocs.io/en/latest/subsystems/sending-messages.htmlfor high-level documentation on this subsystem.@@ -2436,7 +2444,7 @@ def check_message(sender: UserProfile, client: Client, addressee: Addressee,'widget_content': widget_content}message_send_dict = build_message_send_dict(message_dict, email_gateway)- if stream is not None and message_send_dict['message'].mentions_wildcard:+ if stream is not None and message_send_dict.message.mentions_wildcard:if not wildcard_mention_allowed(sender, stream):raise JsonableError(_("You do not have permission to use wildcard mentions in this stream."))return message_send_dict@@ -2445,7 +2453,7 @@ def _internal_prep_message(realm: Realm,sender: UserProfile,addressee: Addressee,content: str,- email_gateway: bool=False) -> Optional[Dict[str, Any]]:+ email_gateway: bool=False) -> Optional[SendMessageRequest]:"""Create a message object and checks it, but doesn't send it or save it to the database.The internal function that calls this can therefore batch send a bunch of created@@ -2478,7 +2486,7 @@ def internal_prep_stream_message(realm: Realm, sender: UserProfile,stream: Stream, topic: str, content: str,email_gateway: bool=False,-) -> Optional[Dict[str, Any]]:+) -> Optional[SendMessageRequest]:"""See _internal_prep_message for details of how this works."""@@ -2495,7 +2503,7 @@ def internal_prep_stream_message(def internal_prep_stream_message_by_name(realm: Realm, sender: UserProfile,stream_name: str, topic: str, content: str,-) -> Optional[Dict[str, Any]]:+) -> Optional[SendMessageRequest]:"""See _internal_prep_message for details of how this works."""@@ -2511,7 +2519,7 @@ def internal_prep_stream_message_by_name(def internal_prep_private_message(realm: Realm,sender: UserProfile,recipient_user: UserProfile,- content: str) -> Optional[Dict[str, Any]]:+ content: str) -> Optional[SendMessageRequest]:"""See _internal_prep_message for details of how this works."""diff --git a/zerver/lib/message.py b/zerver/lib/message.pyindex 2b0a191202b..c1afc2425a4 100644--- a/zerver/lib/message.py+++ b/zerver/lib/message.py@@ -1,6 +1,7 @@import copyimport datetimeimport zlib+from dataclasses import dataclass, fieldfrom typing import Any, Dict, List, Optional, Sequence, Set, Tupleimport ahocorasick@@ -78,6 +79,29 @@ class UnreadMessagesResult(TypedDict):mentions: List[int]count: int+@dataclass+class SendMessageRequest:+ message: Message+ stream: Optional[Stream]+ local_id: Optional[int]+ sender_queue_id: Optional[int]+ realm: Realm+ mention_data: MentionData+ active_user_ids: Set[int]+ push_notify_user_ids: Set[int]+ stream_push_user_ids: Set[int]+ stream_email_user_ids: Set[int]+ um_eligible_user_ids: Set[int]+ long_term_idle_user_ids: Set[int]+ default_bot_user_ids: Set[int]+ service_bot_tuples: List[Tuple[int, int]]+ wildcard_mention_user_ids: Set[int]+ links_for_embed: Set[str]+ widget_content: Optional[Dict[str, Any]]+ submessages: List[Dict[str, Any]] = field(default_factory=list)+ deliver_at: Optional[datetime.datetime] = None+ delivery_type: Optional[str] = None+# We won't try to fetch more unread message IDs from the database than# this limit. The limit is super high, in large part because it means# client-side code mostly doesn't need to think about the case that adiff --git a/zerver/lib/onboarding.py b/zerver/lib/onboarding.pyindex 2a04e31614c..ee4b69a3c79 100644--- a/zerver/lib/onboarding.py+++ b/zerver/lib/onboarding.py@@ -1,4 +1,4 @@-from typing import Any, Dict, List, MutableMapping+from typing import Dict, Listfrom django.conf import settingsfrom django.db.models import Count@@ -12,6 +12,7 @@ from zerver.lib.actions import (internal_send_private_message,)from zerver.lib.emoji import emoji_name_to_emoji_code+from zerver.lib.message import SendMessageRequestfrom zerver.models import Message, Realm, UserProfile, get_system_bot@@ -95,9 +96,9 @@ def send_initial_pms(user: UserProfile) -> None:internal_send_private_message(user.realm, get_system_bot(settings.WELCOME_BOT),user, content)-def send_welcome_bot_response(message: MutableMapping[str, Any]) -> None:+def send_welcome_bot_response(send_request: SendMessageRequest) -> None:welcome_bot = get_system_bot(settings.WELCOME_BOT)- human_recipient_id = message['message'].sender.recipient_id+ human_recipient_id = send_request.message.sender.recipient_idif Message.objects.filter(sender=welcome_bot, recipient_id=human_recipient_id).count() < 2:content = (_("Congratulations on your first reply!") +@@ -109,7 +110,7 @@ def send_welcome_bot_response(message: MutableMapping[str, Any]) -> None:"skills. Or, try clicking on some of the stream names to your left!"))internal_send_private_message(- message['realm'], welcome_bot, message['message'].sender, content)+ send_request.realm, welcome_bot, send_request.message.sender, content)def send_initial_realm_messages(realm: Realm) -> None:welcome_bot = get_system_bot(settings.WELCOME_BOT)diff --git a/zerver/lib/widget.py b/zerver/lib/widget.pyindex a8155797271..55f6fad0bd7 100644--- a/zerver/lib/widget.py+++ b/zerver/lib/widget.py@@ -1,7 +1,8 @@import jsonimport re-from typing import Any, MutableMapping, Optional, Tuple+from typing import Any, Optional, Tuple+from zerver.lib.message import SendMessageRequestfrom zerver.models import SubMessage@@ -42,20 +43,20 @@ def get_extra_data_from_widget_type(content: str,return extra_datareturn None-def do_widget_post_save_actions(message: MutableMapping[str, Any]) -> None:+def do_widget_post_save_actions(send_request: SendMessageRequest) -> None:'''This code works with the webapp; mobile and otherclients should also start supporting this soon.'''- message_content = message['message'].content- sender_id = message['message'].sender_id- message_id = message['message'].id+ message_content = send_request.message.content+ sender_id = send_request.message.sender_id+ message_id = send_request.message.idwidget_type = Noneextra_data = Nonewidget_type, extra_data = get_widget_data(message_content)- widget_content = message.get('widget_content')+ widget_content = send_request.widget_contentif widget_content is not None:# Note that we validate this data in check_message,# so we can trust it here.@@ -74,4 +75,4 @@ def do_widget_post_save_actions(message: MutableMapping[str, Any]) -> None:content=json.dumps(content),)submessage.save()- message['submessages'] = SubMessage.get_raw_db_rows([message_id])+ send_request.submessages = SubMessage.get_raw_db_rows([message_id])diff --git a/zerver/management/commands/deliver_scheduled_messages.py b/zerver/management/commands/deliver_scheduled_messages.pyindex af6303003bc..5efb56f15db 100644--- a/zerver/management/commands/deliver_scheduled_messages.py+++ b/zerver/management/commands/deliver_scheduled_messages.py@@ -1,7 +1,7 @@import loggingimport timefrom datetime import timedelta-from typing import Any, Dict+from typing import Anyfrom django.conf import settingsfrom django.core.management.base import BaseCommand@@ -10,6 +10,7 @@ from django.utils.timezone import now as timezone_nowfrom zerver.lib.actions import build_message_send_dict, do_send_messagesfrom zerver.lib.logging_util import log_to_filefrom zerver.lib.management import sleep_forever+from zerver.lib.message import SendMessageRequestfrom zerver.models import Message, ScheduledMessage, get_user_by_delivery_email## Setup ##@@ -28,7 +29,7 @@ on all but one machine to make the command have no effect.)Usage: ./manage.py deliver_scheduled_messages"""- def construct_message(self, scheduled_message: ScheduledMessage) -> Dict[str, Any]:+ def construct_message(self, scheduled_message: ScheduledMessage) -> SendMessageRequest:message = Message()original_sender = scheduled_message.sendermessage.content = scheduled_message.contentdiff --git a/zerver/tests/test_message_send.py b/zerver/tests/test_message_send.pyindex ea30a84b4fd..bef1931ac89 100644--- a/zerver/tests/test_message_send.py+++ b/zerver/tests/test_message_send.py@@ -1790,7 +1790,7 @@ class InternalPrepTest(ZulipTestCase):recipient_user=recipient_user,content=content)assert result is not None- message = result['message']+ message = result.messageself.assertIn('message was too long', message.content)# Simulate sending a message to somebody not in the@@ -2000,7 +2000,7 @@ class CheckMessageTest(ZulipTestCase):message_content = 'whatever'addressee = Addressee.for_stream_name(stream_name, topic_name)ret = check_message(sender, client, addressee, message_content)- self.assertEqual(ret['message'].sender.id, sender.id)+ self.assertEqual(ret.message.sender.id, sender.id)def test_guest_user_can_send_message(self) -> None:# Guest users can write to web_public streams.@@ -2019,7 +2019,7 @@ class CheckMessageTest(ZulipTestCase):message_content = 'whatever'addressee = Addressee.for_stream_name(rome_stream.name, topic_name)ret = check_message(sender, client, addressee, message_content)- self.assertEqual(ret['message'].sender.id, sender.id)+ self.assertEqual(ret.message.sender.id, sender.id)def test_bot_pm_feature(self) -> None:"""We send a PM to a bot's owner if their bot sends a message to@@ -2069,7 +2069,7 @@ class CheckMessageTest(ZulipTestCase):new_count = message_stream_count(parent)self.assertEqual(new_count, old_count + 2)- self.assertEqual(ret['message'].sender.email, '[email protected]')+ self.assertEqual(ret.message.sender.email, '[email protected]')self.assertIn("does not have any subscribers", most_recent_message(parent).content)def test_bot_pm_error_handling(self) -> None: