A platform for community discussion. Free, open, simple.
DEV: Use same excerpt everywhere in chat (#22319)
Martin Brennan58c8f91d9acf
diff --git a/plugins/chat/app/models/chat/message.rb b/plugins/chat/app/models/chat/message.rbindex b9911713458..8247aa7f2b8 100644--- a/plugins/chat/app/models/chat/message.rb+++ b/plugins/chat/app/models/chat/message.rb@@ -127,32 +127,12 @@ module Chat# upload-only messages are better represented as the filenamereturn uploads.first.original_filename if cooked.blank? && uploads.present?- # this may return blank for some complex things like quotes, that is acceptable- PrettyText.excerpt(message, max_length, { text_entities: true })- end-- # TODO (martin) Replace the above #excerpt method usage with this one. The- # issue with the above one is that we cannot actually render nice HTML- # fore replies/excerpts in the UI because text_entities: true will- # allow through even denied HTML because of 07ab20131a15ab907c1974fee405d9bdce0c0723.- #- # For now only the thread index uses this new version since it is not interactive,- # we can go back to the interactive reply/edit cases in another PR.- def rich_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)-- # upload-only messages are better represented as the filename- return uploads.first.original_filename if cooked.blank? && uploads.present?-# this may return blank for some complex things like quotes, that is acceptablePrettyText.excerpt(cooked, max_length)end- def censored_excerpt(rich: false, max_length: 50)- WordWatcher.censor(- rich ? rich_excerpt(max_length: max_length) : excerpt(max_length: max_length),- )+ def censored_excerpt(max_length: 50)+ WordWatcher.censor(excerpt(max_length: max_length))enddef cooked_for_excerptdiff --git a/plugins/chat/app/models/chat/thread.rb b/plugins/chat/app/models/chat/thread.rbindex bd0f944b8e0..a880f17508e 100644--- a/plugins/chat/app/models/chat/thread.rb+++ b/plugins/chat/app/models/chat/thread.rb@@ -68,7 +68,7 @@ module Chatenddef excerpt- original_message.rich_excerpt(max_length: EXCERPT_LENGTH)+ original_message.excerpt(max_length: EXCERPT_LENGTH)enddef latest_not_deleted_message_id(anchor_message_id: nil)diff --git a/plugins/chat/app/serializers/chat/thread_original_message_serializer.rb b/plugins/chat/app/serializers/chat/thread_original_message_serializer.rbindex 8500fba6bc6..0577290f8b5 100644--- a/plugins/chat/app/serializers/chat/thread_original_message_serializer.rb+++ b/plugins/chat/app/serializers/chat/thread_original_message_serializer.rb@@ -5,7 +5,7 @@ module Chathas_one :user, serializer: BasicUserWithStatusSerializer, embed: :objectsdef excerpt- object.censored_excerpt(rich: true, max_length: Chat::Thread::EXCERPT_LENGTH)+ object.censored_excerpt(max_length: Chat::Thread::EXCERPT_LENGTH)enddef include_available_flags?diff --git a/plugins/chat/app/serializers/chat/thread_preview_serializer.rb b/plugins/chat/app/serializers/chat/thread_preview_serializer.rbindex dbf132954e8..53355c0d3f6 100644--- a/plugins/chat/app/serializers/chat/thread_preview_serializer.rb+++ b/plugins/chat/app/serializers/chat/thread_preview_serializer.rb@@ -28,7 +28,7 @@ module Chatenddef last_reply_excerpt- object.last_reply.censored_excerpt(rich: true, max_length: Chat::Thread::EXCERPT_LENGTH)+ object.last_reply.excerpt(max_length: Chat::Thread::EXCERPT_LENGTH)enddef last_reply_userdiff --git a/plugins/chat/spec/plugin_helper.rb b/plugins/chat/spec/plugin_helper.rbindex b64ecc022a6..378ff17921d 100644--- a/plugins/chat/spec/plugin_helper.rb+++ b/plugins/chat/spec/plugin_helper.rb@@ -56,10 +56,7 @@ module ChatSystemHelpersdef thread_excerpt(message)CGI.escapeHTML(- message.censored_excerpt(rich: true, max_length: ::Chat::Thread::EXCERPT_LENGTH).gsub(- "…",- "…",- ),+ message.censored_excerpt(max_length: ::Chat::Thread::EXCERPT_LENGTH).gsub("…", "…"),)endenddiff --git a/plugins/chat/spec/system/chat/composer/channel_spec.rb b/plugins/chat/spec/system/chat/composer/channel_spec.rbindex 3668e4f0f49..0f6980ca6a1 100644--- a/plugins/chat/spec/system/chat/composer/channel_spec.rb+++ b/plugins/chat/spec/system/chat/composer/channel_spec.rb@@ -18,12 +18,13 @@ RSpec.describe "Chat | composer | channel", type: :system, js: true dodescribe "reply to message" doit "renders text in the details" domessage_1.update!(message: "<mark>not marked</mark>")+ message_1.rebake!chat_page.visit_channel(channel_1)channel_page.reply_to(message_1)expect(channel_page.composer.message_details).to have_message(id: message_1.id,- exact_text: "not marked",+ exact_text: "<mark>not marked</mark>",)enddiff --git a/plugins/chat/spec/system/chat_channel_spec.rb b/plugins/chat/spec/system/chat_channel_spec.rbindex e6f4d0bc062..87bb7ab4117 100644--- a/plugins/chat/spec/system/chat_channel_spec.rb+++ b/plugins/chat/spec/system/chat_channel_spec.rb@@ -240,7 +240,9 @@ RSpec.describe "Chat channel", type: :system doit "renders text in the reply-to" dochat.visit_channel(channel_1)- expect(find(".chat-reply .chat-reply__excerpt")["innerHTML"].strip).to eq("not marked")+ expect(find(".chat-reply .chat-reply__excerpt")["innerHTML"].strip).to eq(+ "&lt;mark&gt;not marked&lt;/mark&gt;",+ )endend