diff --git a/plugins/chat/app/serializers/chat_thread_serializer.rb b/plugins/chat/app/serializers/chat_thread_serializer.rb index 614f5d79db..48e06205e6 100644 --- a/plugins/chat/app/serializers/chat_thread_serializer.rb +++ b/plugins/chat/app/serializers/chat_thread_serializer.rb @@ -4,5 +4,14 @@ class ChatThreadSerializer < ApplicationSerializer has_one :original_message_user, serializer: BasicUserWithStatusSerializer, embed: :objects has_one :original_message, serializer: ChatThreadOriginalMessageSerializer, embed: :objects - attributes :id, :title, :status + attributes :id, :title, :status, :messages + + def messages + ActiveModel::ArraySerializer.new( + object.chat_messages.order(:created_at).last(50), + each_serializer: ChatMessageSerializer, + chat_channel: object.channel, + scope: scope, + ) + 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 3238d28a61..549231139c 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-thread.hbs +++ b/plugins/chat/assets/javascripts/discourse/components/chat-thread.hbs @@ -32,5 +32,13 @@
\ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/routes/chat-channel-thread.js b/plugins/chat/assets/javascripts/discourse/routes/chat-channel-thread.js index 8621dc311d..7da51f128a 100644 --- a/plugins/chat/assets/javascripts/discourse/routes/chat-channel-thread.js +++ b/plugins/chat/assets/javascripts/discourse/routes/chat-channel-thread.js @@ -1,5 +1,6 @@ import DiscourseRoute from "discourse/routes/discourse"; import { inject as service } from "@ember/service"; +import ChatMessage from "discourse/plugins/chat/discourse/models/chat-message"; export default class ChatChannelThread extends DiscourseRoute { @service router; @@ -17,5 +18,8 @@ export default class ChatChannelThread extends DiscourseRoute { afterModel(model) { this.chat.activeThread = model; this.chatStateManager.openSidePanel(); + this.chat.activeThread.messages = ( + this.chat.activeThread.messages || [] + ).map((message) => ChatMessage.create(message)); } }