discourse/app/serializers/topic_list_item_serializer.rb
2014-02-10 16:07:09 +11:00

27 lines
597 B
Ruby

class TopicListItemSerializer < ListableTopicSerializer
attributes :views,
:like_count,
:starred,
:has_summary,
:archetype,
:last_poster_username,
:category_id
has_many :posters, serializer: TopicPosterSerializer, embed: :objects
def starred
object.user_data.starred?
end
alias :include_starred? :has_user_data
def posters
object.posters || []
end
def last_poster_username
object.posters.find { |poster| poster.user.id == object.last_post_user_id }.try(:user).try(:username)
end
end