mirror of
https://github.com/discourse/discourse.git
synced 2025-06-03 02:48:28 +08:00
FEATURE: sorting by op likes shows the op likes count
This commit is contained in:
@ -6,7 +6,8 @@ class TopicListItemSerializer < ListableTopicSerializer
|
||||
:has_summary,
|
||||
:archetype,
|
||||
:last_poster_username,
|
||||
:category_id
|
||||
:category_id,
|
||||
:op_like_count
|
||||
|
||||
has_many :posters, serializer: TopicPosterSerializer, embed: :objects
|
||||
has_many :participants, serializer: TopicPosterSerializer, embed: :objects
|
||||
@ -21,6 +22,10 @@ class TopicListItemSerializer < ListableTopicSerializer
|
||||
object.posters || []
|
||||
end
|
||||
|
||||
def op_like_count
|
||||
object.first_post && object.first_post.like_count
|
||||
end
|
||||
|
||||
def last_poster_username
|
||||
posters.find { |poster| poster.user.id == object.last_post_user_id }.try(:user).try(:username)
|
||||
end
|
||||
@ -33,4 +38,8 @@ class TopicListItemSerializer < ListableTopicSerializer
|
||||
object.private_message?
|
||||
end
|
||||
|
||||
def include_op_like_count?
|
||||
object.association(:first_post).loaded?
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user