This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/plugins/chat/app/serializers/chat_thread_serializer.rb
2023-02-13 12:51:39 +10:00

18 lines
543 B
Ruby

# frozen_string_literal: true
class ChatThreadSerializer < ApplicationSerializer
has_one :original_message_user, serializer: BasicUserWithStatusSerializer, embed: :objects
has_one :original_message, serializer: ChatThreadOriginalMessageSerializer, embed: :objects
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