diff --git a/plugins/chat/app/models/chat_message.rb b/plugins/chat/app/models/chat_message.rb index 145144ad79..39d7c0ab98 100644 --- a/plugins/chat/app/models/chat_message.rb +++ b/plugins/chat/app/models/chat_message.rb @@ -82,7 +82,7 @@ class ChatMessage < ActiveRecord::Base UploadReference.insert_all!(ref_record_attrs) end - def excerpt + def excerpt(max_length: 50) # just show the URL if the whole message is a URL, because we cannot excerpt oneboxes return message if UrlHelper.relaxed_parse(message).is_a?(URI) @@ -90,7 +90,7 @@ class ChatMessage < ActiveRecord::Base return uploads.first.original_filename if cooked.blank? && uploads.present? # this may return blank for some complex things like quotes, that is acceptable - PrettyText.excerpt(cooked, 50, { text_entities: true }) + PrettyText.excerpt(cooked, max_length, { text_entities: true }) end def cooked_for_excerpt diff --git a/plugins/chat/app/models/chat_thread.rb b/plugins/chat/app/models/chat_thread.rb index 53d685d98f..c320281728 100644 --- a/plugins/chat/app/models/chat_thread.rb +++ b/plugins/chat/app/models/chat_thread.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class ChatThread < ActiveRecord::Base + EXCERPT_LENGTH = 150 + belongs_to :channel, foreign_key: "channel_id", class_name: "ChatChannel" belongs_to :original_message_user, foreign_key: "original_message_user_id", class_name: "User" belongs_to :original_message, foreign_key: "original_message_id", class_name: "ChatMessage" @@ -19,6 +21,10 @@ class ChatThread < ActiveRecord::Base def relative_url "#{channel.relative_url}/t/#{self.id}" end + + def excerpt + original_message.excerpt(max_length: EXCERPT_LENGTH) + end end # == Schema Information diff --git a/plugins/chat/app/serializers/chat_thread_original_message_serializer.rb b/plugins/chat/app/serializers/chat_thread_original_message_serializer.rb index eb773e19db..0cbf498bcc 100644 --- a/plugins/chat/app/serializers/chat_thread_original_message_serializer.rb +++ b/plugins/chat/app/serializers/chat_thread_original_message_serializer.rb @@ -6,6 +6,6 @@ class ChatThreadOriginalMessageSerializer < ApplicationSerializer has_one :chat_webhook_event, serializer: ChatWebhookEventSerializer, embed: :objects def excerpt - WordWatcher.censor(object.excerpt) + WordWatcher.censor(object.excerpt(max_length: ChatThread::EXCERPT_LENGTH)) end end diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-thread.hbs b/plugins/chat/assets/javascripts/discourse/components/chat-thread.hbs index 7ae72eadba..9121044398 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-thread.hbs +++ b/plugins/chat/assets/javascripts/discourse/components/chat-thread.hbs @@ -18,6 +18,9 @@