mirror of
https://github.com/zulip/zulip.git
synced 2025-11-21 15:09:34 +00:00
Extract _internal_prep_message().
The function internal_prep_message is kind of awkward to call, so I'm moving most of its implementation to _internal_prep_message() for upcoming refactorings.
This commit is contained in:
@@ -1239,9 +1239,9 @@ def check_message(sender, client, message_type_name, message_to,
|
|||||||
return {'message': message, 'stream': stream, 'local_id': local_id,
|
return {'message': message, 'stream': stream, 'local_id': local_id,
|
||||||
'sender_queue_id': sender_queue_id, 'realm': realm}
|
'sender_queue_id': sender_queue_id, 'realm': realm}
|
||||||
|
|
||||||
def internal_prep_message(realm, sender_email, recipient_type_name, recipients,
|
def _internal_prep_message(realm, sender, recipient_type_name, parsed_recipients,
|
||||||
subject, content):
|
subject, content):
|
||||||
# type: (Realm, Text, str, Text, Text, Text) -> Optional[Dict[str, Any]]
|
# type: (Realm, UserProfile, str, List[Text], Text, Text) -> Optional[Dict[str, Any]]
|
||||||
"""
|
"""
|
||||||
Create a message object and checks it, but doesn't send it or save it to the database.
|
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
|
The internal function that calls this can therefore batch send a bunch of created
|
||||||
@@ -1251,10 +1251,9 @@ def internal_prep_message(realm, sender_email, recipient_type_name, recipients,
|
|||||||
if len(content) > MAX_MESSAGE_LENGTH:
|
if len(content) > MAX_MESSAGE_LENGTH:
|
||||||
content = content[0:3900] + "\n\n[message was too long and has been truncated]"
|
content = content[0:3900] + "\n\n[message was too long and has been truncated]"
|
||||||
|
|
||||||
sender = get_user_profile_by_email(sender_email)
|
|
||||||
if realm is None:
|
if realm is None:
|
||||||
raise RuntimeError("None is not a valid realm for internal_prep_message!")
|
raise RuntimeError("None is not a valid realm for internal_prep_message!")
|
||||||
parsed_recipients = extract_recipients(recipients)
|
|
||||||
if recipient_type_name == "stream":
|
if recipient_type_name == "stream":
|
||||||
stream, _ = create_stream_if_needed(realm, parsed_recipients[0])
|
stream, _ = create_stream_if_needed(realm, parsed_recipients[0])
|
||||||
|
|
||||||
@@ -1262,10 +1261,28 @@ def internal_prep_message(realm, sender_email, recipient_type_name, recipients,
|
|||||||
return check_message(sender, get_client("Internal"), recipient_type_name,
|
return check_message(sender, get_client("Internal"), recipient_type_name,
|
||||||
parsed_recipients, subject, content, realm=realm)
|
parsed_recipients, subject, content, realm=realm)
|
||||||
except JsonableError as e:
|
except JsonableError as e:
|
||||||
logging.error("Error queueing internal message by %s: %s" % (sender_email, str(e)))
|
logging.error("Error queueing internal message by %s: %s" % (sender.email, str(e)))
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def internal_prep_message(realm, sender_email, recipient_type_name, recipients,
|
||||||
|
subject, content):
|
||||||
|
# type: (Realm, Text, str, Text, Text, Text) -> Optional[Dict[str, Any]]
|
||||||
|
"""
|
||||||
|
See _internal_prep_message for details of how this works.
|
||||||
|
"""
|
||||||
|
sender = get_user_profile_by_email(sender_email)
|
||||||
|
parsed_recipients = extract_recipients(recipients)
|
||||||
|
|
||||||
|
return _internal_prep_message(
|
||||||
|
realm=realm,
|
||||||
|
sender=sender,
|
||||||
|
recipient_type_name=recipient_type_name,
|
||||||
|
parsed_recipients=parsed_recipients,
|
||||||
|
subject=subject,
|
||||||
|
content=content,
|
||||||
|
)
|
||||||
|
|
||||||
def internal_send_message(realm, sender_email, recipient_type_name, recipients,
|
def internal_send_message(realm, sender_email, recipient_type_name, recipients,
|
||||||
subject, content):
|
subject, content):
|
||||||
# type: (Realm, Text, str, Text, Text, Text) -> None
|
# type: (Realm, Text, str, Text, Text, Text) -> None
|
||||||
|
|||||||
Reference in New Issue
Block a user