2013-03-14 14:45:29 -04:00
|
|
|
class TopicListItemSerializer < ListableTopicSerializer
|
2013-02-05 14:16:51 -05:00
|
|
|
|
2013-02-25 11:42:20 -05:00
|
|
|
attributes :views,
|
|
|
|
:like_count,
|
|
|
|
:starred,
|
2013-11-18 12:48:26 -05:00
|
|
|
:has_summary,
|
2013-04-02 16:52:51 -04:00
|
|
|
:archetype,
|
2013-10-23 14:40:39 -04:00
|
|
|
:last_poster_username,
|
2015-01-05 01:39:49 -05:00
|
|
|
:category_id,
|
2015-01-05 15:43:05 -05:00
|
|
|
:op_like_count,
|
|
|
|
:pinned_globally
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
has_many :posters, serializer: TopicPosterSerializer, embed: :objects
|
2014-05-12 03:32:49 -04:00
|
|
|
has_many :participants, serializer: TopicPosterSerializer, embed: :objects
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
def starred
|
|
|
|
object.user_data.starred?
|
|
|
|
end
|
2014-05-12 03:32:49 -04:00
|
|
|
|
2014-02-10 00:07:09 -05:00
|
|
|
alias :include_starred? :has_user_data
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
def posters
|
|
|
|
object.posters || []
|
|
|
|
end
|
|
|
|
|
2015-01-05 01:39:49 -05:00
|
|
|
def op_like_count
|
|
|
|
object.first_post && object.first_post.like_count
|
|
|
|
end
|
|
|
|
|
2013-09-19 16:25:25 -04:00
|
|
|
def last_poster_username
|
2014-09-02 22:13:13 -04:00
|
|
|
posters.find { |poster| poster.user.id == object.last_post_user_id }.try(:user).try(:username)
|
2013-09-19 16:25:25 -04:00
|
|
|
end
|
|
|
|
|
2014-05-12 03:32:49 -04:00
|
|
|
def participants
|
|
|
|
object.participants_summary || []
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_participants?
|
|
|
|
object.private_message?
|
|
|
|
end
|
|
|
|
|
2015-01-05 01:39:49 -05:00
|
|
|
def include_op_like_count?
|
2015-01-05 01:54:38 -05:00
|
|
|
# PERF: long term we probably want a cheaper way of looking stuff up
|
|
|
|
# this is rather odd code, but we need to have op_likes loaded somehow
|
|
|
|
# simplest optimisation is adding a cache column on topic.
|
2015-01-05 01:39:49 -05:00
|
|
|
object.association(:first_post).loaded?
|
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|