mirror of
https://github.com/discourse/discourse.git
synced 2026-08-12 05:55:39 -05:00
DEV: cooks messages synchronously (#24510)
Mentions and other post processing (like images) are still done asynchronously in the background. This should ensure reloading a channel while the message has not been processed yet doesn’t renders a blank message. As a followup, we could probably simplify the staged message logic, given we have the new cooked on send.
This commit is contained in:
@@ -132,6 +132,8 @@ module Chat
|
||||
message: contract.message,
|
||||
uploads: uploads,
|
||||
thread: thread,
|
||||
cooked: ::Chat::Message.cook(contract.message, user_id: guardian.user.id),
|
||||
cooked_version: ::Chat::Message::BAKED_VERSION,
|
||||
)
|
||||
end
|
||||
|
||||
@@ -182,6 +184,14 @@ module Chat
|
||||
end
|
||||
|
||||
def process(channel:, message_instance:, contract:, **)
|
||||
::Chat::Publisher.publish_new!(channel, message_instance, contract.staged_id)
|
||||
DiscourseEvent.trigger(
|
||||
:chat_message_created,
|
||||
message_instance,
|
||||
channel,
|
||||
message_instance.user,
|
||||
)
|
||||
|
||||
if contract.process_inline
|
||||
Jobs::Chat::ProcessMessage.new.execute(
|
||||
{ chat_message_id: message_instance.id, staged_id: contract.staged_id },
|
||||
|
||||
@@ -109,7 +109,7 @@ module Chat
|
||||
publish_to_targets!(
|
||||
message_bus_targets,
|
||||
chat_channel,
|
||||
{ type: :processed, chat_message: { id: chat_message.id, cooked: chat_message.cooked } },
|
||||
serialize_message_with_type(chat_message, :processed),
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
@@ -81,6 +81,7 @@ module Chat
|
||||
def modify_message(contract:, message:, guardian:, uploads:, **)
|
||||
message.message = contract.message
|
||||
message.last_editor_id = guardian.user.id
|
||||
message.cook
|
||||
|
||||
return if uploads&.size != contract.upload_ids.to_a.size
|
||||
|
||||
@@ -133,6 +134,9 @@ module Chat
|
||||
def publish(message:, guardian:, contract:, **)
|
||||
edit_timestamp = context.revision&.created_at&.iso8601(6) || Time.zone.now.iso8601(6)
|
||||
|
||||
::Chat::Publisher.publish_edit!(message.chat_channel, message)
|
||||
DiscourseEvent.trigger(:chat_message_edited, message, message.chat_channel, message.user)
|
||||
|
||||
if contract.process_inline
|
||||
Jobs::Chat::ProcessMessage.new.execute(
|
||||
{ chat_message_id: message.id, edit_timestamp: edit_timestamp },
|
||||
|
||||
Reference in New Issue
Block a user