mirror of
https://github.com/zulip/zulip.git
synced 2025-11-07 07:23:22 +00:00
rendering: Consolidate code to render new messages.
We now use render_incoming_message() to render all incoming new messages (sends/edits), so that they will get the same treatment. This change also establishes do_send_messages() as the code path to get new messages rendered. It removes some logic from check_message() that only happened on certain code paths for sending messages, and which would only detect failures by expensively rendering messages, so it wasn't much of a guard. This change also helps to phase out maybe_render_content(), which deepens the call stack without providing much clarity to the reader, since it's behavior is so variable. Finally, this sets up to fix a flaw in the way we compute which users have alert words in their messages (in a subsequent commit).
This commit is contained in:
@@ -627,6 +627,14 @@ def do_send_message(message, rendered_content = None, no_log = False, stream = N
|
|||||||
'stream': stream,
|
'stream': stream,
|
||||||
'local_id': local_id}])[0]
|
'local_id': local_id}])[0]
|
||||||
|
|
||||||
|
def render_incoming_message(message, content):
|
||||||
|
# type: (Message, text_type) -> text_type
|
||||||
|
try:
|
||||||
|
rendered_content = message.render_markdown(content)
|
||||||
|
except BugdownRenderingException:
|
||||||
|
raise JsonableError(_('Unable to render message'))
|
||||||
|
return rendered_content
|
||||||
|
|
||||||
def do_send_messages(messages):
|
def do_send_messages(messages):
|
||||||
# type: (Sequence[Optional[MutableMapping[str, Any]]]) -> List[int]
|
# type: (Sequence[Optional[MutableMapping[str, Any]]]) -> List[int]
|
||||||
# Filter out messages which didn't pass internal_prep_message properly
|
# Filter out messages which didn't pass internal_prep_message properly
|
||||||
@@ -685,7 +693,16 @@ def do_send_messages(messages):
|
|||||||
# Only deliver the message to active user recipients
|
# Only deliver the message to active user recipients
|
||||||
message['active_recipients'] = [user_profile for user_profile in message['recipients']
|
message['active_recipients'] = [user_profile for user_profile in message['recipients']
|
||||||
if user_profile.is_active]
|
if user_profile.is_active]
|
||||||
message['message'].maybe_render_content(None)
|
|
||||||
|
# Render our messages.
|
||||||
|
for message in messages:
|
||||||
|
assert message['message'].rendered_content is None
|
||||||
|
rendered_content = render_incoming_message(
|
||||||
|
message['message'],
|
||||||
|
message['message'].content)
|
||||||
|
message['message'].set_rendered_content(rendered_content)
|
||||||
|
|
||||||
|
for message in messages:
|
||||||
message['message'].update_calculated_fields()
|
message['message'].update_calculated_fields()
|
||||||
|
|
||||||
# Save the message receipts in the database
|
# Save the message receipts in the database
|
||||||
@@ -1065,10 +1082,8 @@ def check_message(sender, client, message_type_name, message_to,
|
|||||||
message.pub_date = timezone.now()
|
message.pub_date = timezone.now()
|
||||||
message.sending_client = client
|
message.sending_client = client
|
||||||
|
|
||||||
try:
|
# We render messages later in the process.
|
||||||
message.maybe_render_content(realm.domain)
|
assert message.rendered_content is None
|
||||||
except BugdownRenderingException:
|
|
||||||
raise JsonableError(_("Unable to render message"))
|
|
||||||
|
|
||||||
if client.name == "zephyr_mirror":
|
if client.name == "zephyr_mirror":
|
||||||
id = already_sent_mirrored_message_id(message)
|
id = already_sent_mirrored_message_id(message)
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ from zerver.lib import bugdown
|
|||||||
from zerver.lib.actions import recipient_for_emails, do_update_message_flags, \
|
from zerver.lib.actions import recipient_for_emails, do_update_message_flags, \
|
||||||
compute_mit_user_fullname, compute_irc_user_fullname, compute_jabber_user_fullname, \
|
compute_mit_user_fullname, compute_irc_user_fullname, compute_jabber_user_fullname, \
|
||||||
create_mirror_user_if_needed, check_send_message, do_update_message, \
|
create_mirror_user_if_needed, check_send_message, do_update_message, \
|
||||||
extract_recipients, truncate_body
|
extract_recipients, truncate_body, render_incoming_message
|
||||||
from zerver.lib.cache import generic_bulk_cached_fetch
|
from zerver.lib.cache import generic_bulk_cached_fetch
|
||||||
from zerver.lib.response import json_success, json_error
|
from zerver.lib.response import json_success, json_error
|
||||||
from zerver.lib.sqlalchemy_utils import get_sqlalchemy_connection
|
from zerver.lib.sqlalchemy_utils import get_sqlalchemy_connection
|
||||||
@@ -910,9 +910,9 @@ def update_message_backend(request, user_profile,
|
|||||||
if content == "":
|
if content == "":
|
||||||
raise JsonableError(_("Content can't be empty"))
|
raise JsonableError(_("Content can't be empty"))
|
||||||
content = truncate_body(content)
|
content = truncate_body(content)
|
||||||
rendered_content = message.render_markdown(content)
|
|
||||||
if not rendered_content:
|
# If rendering fails, the called code will raise a JsonableError.
|
||||||
raise JsonableError(_("We were unable to render your updated message"))
|
rendered_content = render_incoming_message(message, content)
|
||||||
|
|
||||||
do_update_message(user_profile, message, subject, propagate_mode, content, rendered_content)
|
do_update_message(user_profile, message, subject, propagate_mode, content, rendered_content)
|
||||||
return json_success()
|
return json_success()
|
||||||
|
|||||||
Reference in New Issue
Block a user