mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
This commit adds the initial part of thread indicator improvements: * Show the reply count, last reply date and excerpt, and the participants of the thread's avatars and count of additional participants * Add a participants component for the thread that can be reused for the list * Add a query class to get the thread participants * Live update the thread indicator more consistently with the last reply and participant details image image In subsequent PRs we will cache the participants since they do not change often, and improve the thread list further with participants. This commit also adds a showPresence boolean (default true) to ChatUserAvatar, since we don't want to show the online indicator for thread participants. --------- Co-authored-by: chapoi <charlie@discourse.org>
68 lines
1.6 KiB
Ruby
68 lines
1.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Chat
|
|
class ThreadSerializer < ApplicationSerializer
|
|
has_one :original_message, serializer: Chat::ThreadOriginalMessageSerializer, embed: :objects
|
|
|
|
attributes :id,
|
|
:title,
|
|
:status,
|
|
:channel_id,
|
|
:meta,
|
|
:reply_count,
|
|
:current_user_membership,
|
|
:preview
|
|
|
|
def initialize(object, opts)
|
|
super(object, opts)
|
|
@opts = opts
|
|
|
|
# Avoids an N1 to re-load the thread in the serializer for original_message.
|
|
object.original_message&.thread = object
|
|
@current_user_membership = opts[:membership]
|
|
end
|
|
|
|
def meta
|
|
{ message_bus_last_ids: { thread_message_bus_last_id: thread_message_bus_last_id } }
|
|
end
|
|
|
|
def reply_count
|
|
object.replies_count_cache || 0
|
|
end
|
|
|
|
def include_preview?
|
|
@opts[:include_preview]
|
|
end
|
|
|
|
def preview
|
|
Chat::ThreadPreviewSerializer.new(
|
|
object,
|
|
scope: scope,
|
|
root: false,
|
|
participants: @opts[:participants],
|
|
).as_json
|
|
end
|
|
|
|
def include_current_user_membership?
|
|
@current_user_membership.present?
|
|
end
|
|
|
|
def current_user_membership
|
|
@current_user_membership.thread = object
|
|
|
|
Chat::BaseThreadMembershipSerializer.new(
|
|
@current_user_membership,
|
|
scope: scope,
|
|
root: false,
|
|
).as_json
|
|
end
|
|
|
|
private
|
|
|
|
def thread_message_bus_last_id
|
|
@opts[:thread_message_bus_last_id] ||
|
|
MessageBus.last_id(Chat::Publisher.thread_message_bus_channel(object.channel_id, object.id))
|
|
end
|
|
end
|
|
end
|