From 588e812d3316c4f5bbbde980e096bd7d2c829cfd Mon Sep 17 00:00:00 2001
From: Martin Brennan
Date: Thu, 9 Feb 2023 14:07:31 +1000
Subject: [PATCH] DEV: Add started by and avatar align and more specs
---
plugins/chat/app/models/chat_message.rb | 4 ++--
plugins/chat/app/models/chat_thread.rb | 6 ++++++
.../chat_thread_original_message_serializer.rb | 2 +-
.../discourse/components/chat-thread.hbs | 3 +++
.../stylesheets/common/chat-thread-panel.scss | 8 --------
.../assets/stylesheets/common/chat-thread.scss | 14 ++++++++++++++
plugins/chat/config/locales/client.en.yml | 1 +
plugins/chat/plugin.rb | 1 -
.../spec/system/page_objects/chat/chat_thread.rb | 10 +++++++++-
plugins/chat/spec/system/single_thread_spec.rb | 9 ++++++++-
10 files changed, 44 insertions(+), 14 deletions(-)
delete mode 100644 plugins/chat/assets/stylesheets/common/chat-thread-panel.scss
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 @@
+ {{i18n
+ "chat.threads.started_by"
+ }}