2013-03-15 02:45:29 +08:00
|
|
|
class TopicListItemSerializer < ListableTopicSerializer
|
2013-02-06 03:16:51 +08:00
|
|
|
|
2013-02-26 00:42:20 +08:00
|
|
|
attributes :views,
|
|
|
|
:like_count,
|
|
|
|
:starred,
|
2013-11-19 01:48:26 +08:00
|
|
|
:has_summary,
|
2013-04-03 04:52:51 +08:00
|
|
|
:archetype,
|
2013-10-24 02:40:39 +08:00
|
|
|
:last_poster_username,
|
2015-01-05 14:39:49 +08:00
|
|
|
:category_id,
|
|
|
|
:op_like_count
|
2013-02-06 03:16:51 +08:00
|
|
|
|
|
|
|
has_many :posters, serializer: TopicPosterSerializer, embed: :objects
|
2014-05-12 15:32:49 +08:00
|
|
|
has_many :participants, serializer: TopicPosterSerializer, embed: :objects
|
2013-02-06 03:16:51 +08:00
|
|
|
|
|
|
|
def starred
|
|
|
|
object.user_data.starred?
|
|
|
|
end
|
2014-05-12 15:32:49 +08:00
|
|
|
|
2014-02-10 13:07:09 +08:00
|
|
|
alias :include_starred? :has_user_data
|
2013-02-06 03:16:51 +08:00
|
|
|
|
|
|
|
def posters
|
|
|
|
object.posters || []
|
|
|
|
end
|
|
|
|
|
2015-01-05 14:39:49 +08:00
|
|
|
def op_like_count
|
|
|
|
object.first_post && object.first_post.like_count
|
|
|
|
end
|
|
|
|
|
2013-09-20 04:25:25 +08:00
|
|
|
def last_poster_username
|
2014-09-03 10:13:13 +08:00
|
|
|
posters.find { |poster| poster.user.id == object.last_post_user_id }.try(:user).try(:username)
|
2013-09-20 04:25:25 +08:00
|
|
|
end
|
|
|
|
|
2014-05-12 15:32:49 +08:00
|
|
|
def participants
|
|
|
|
object.participants_summary || []
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_participants?
|
|
|
|
object.private_message?
|
|
|
|
end
|
|
|
|
|
2015-01-05 14:39:49 +08:00
|
|
|
def include_op_like_count?
|
|
|
|
object.association(:first_post).loaded?
|
|
|
|
end
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|