discourse/plugins/chat/app/jobs/regular/process_chat_message.rb
Roman Rizzi 0a5f548635
DEV: Move discourse-chat to the core repo. (#18776)
As part of this move, we are also renaming `discourse-chat` to `chat`.
2022-11-02 10:41:30 -03:00

23 lines
681 B
Ruby

# frozen_string_literal: true
module Jobs
class ProcessChatMessage < ::Jobs::Base
def execute(args = {})
DistributedMutex.synchronize(
"process_chat_message_#{args[:chat_message_id]}",
validity: 10.minutes,
) do
chat_message = ChatMessage.find_by(id: args[:chat_message_id])
return if !chat_message
processor = Chat::ChatMessageProcessor.new(chat_message)
processor.run!
if args[:is_dirty] || processor.dirty?
chat_message.update(cooked: processor.html, cooked_version: ChatMessage::BAKED_VERSION)
ChatPublisher.publish_processed!(chat_message)
end
end
end
end
end