2013-03-14 13:45:29 -05:00
|
|
|
class TopicListItemSerializer < ListableTopicSerializer
|
2013-02-05 13:16:51 -06:00
|
|
|
|
2013-02-25 10:42:20 -06:00
|
|
|
attributes :views,
|
|
|
|
:like_count,
|
2013-11-18 11:48:26 -06:00
|
|
|
:has_summary,
|
2013-04-02 15:52:51 -05:00
|
|
|
:archetype,
|
2013-10-23 13:40:39 -05:00
|
|
|
:last_poster_username,
|
2015-01-05 00:39:49 -06:00
|
|
|
:category_id,
|
2015-01-05 14:43:05 -06:00
|
|
|
:op_like_count,
|
2015-01-07 01:20:10 -06:00
|
|
|
:pinned_globally,
|
2015-01-07 01:50:28 -06:00
|
|
|
:bookmarked_post_numbers,
|
2016-04-25 14:55:15 -05:00
|
|
|
:liked_post_numbers,
|
2016-12-05 06:31:43 -06:00
|
|
|
:tags,
|
|
|
|
:featured_link
|
2013-02-05 13:16:51 -06:00
|
|
|
|
|
|
|
has_many :posters, serializer: TopicPosterSerializer, embed: :objects
|
2014-05-12 02:32:49 -05:00
|
|
|
has_many :participants, serializer: TopicPosterSerializer, embed: :objects
|
2013-02-05 13:16:51 -06:00
|
|
|
|
|
|
|
def posters
|
|
|
|
object.posters || []
|
|
|
|
end
|
|
|
|
|
2015-01-05 00:39:49 -06:00
|
|
|
def op_like_count
|
|
|
|
object.first_post && object.first_post.like_count
|
|
|
|
end
|
|
|
|
|
2013-09-19 15:25:25 -05:00
|
|
|
def last_poster_username
|
2014-09-02 21:13:13 -05:00
|
|
|
posters.find { |poster| poster.user.id == object.last_post_user_id }.try(:user).try(:username)
|
2013-09-19 15:25:25 -05:00
|
|
|
end
|
|
|
|
|
2014-05-12 02:32:49 -05:00
|
|
|
def participants
|
|
|
|
object.participants_summary || []
|
|
|
|
end
|
|
|
|
|
2015-01-07 01:20:10 -06:00
|
|
|
def include_bookmarked_post_numbers?
|
2015-01-07 01:50:28 -06:00
|
|
|
include_post_action? :bookmark
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_liked_post_numbers?
|
|
|
|
include_post_action? :like
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_post_action?(action)
|
2015-01-07 01:20:10 -06:00
|
|
|
object.user_data &&
|
|
|
|
object.user_data.post_action_data &&
|
2015-01-07 01:50:28 -06:00
|
|
|
object.user_data.post_action_data.key?(PostActionType.types[action])
|
|
|
|
end
|
|
|
|
|
|
|
|
def liked_post_numbers
|
|
|
|
object.user_data.post_action_data[PostActionType.types[:like]]
|
2015-01-07 01:20:10 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def bookmarked_post_numbers
|
|
|
|
object.user_data.post_action_data[PostActionType.types[:bookmark]]
|
|
|
|
end
|
|
|
|
|
2014-05-12 02:32:49 -05:00
|
|
|
def include_participants?
|
|
|
|
object.private_message?
|
|
|
|
end
|
|
|
|
|
2015-01-05 00:39:49 -06:00
|
|
|
def include_op_like_count?
|
2015-01-05 00:54:38 -06: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 00:39:49 -06:00
|
|
|
object.association(:first_post).loaded?
|
|
|
|
end
|
|
|
|
|
2016-04-25 14:55:15 -05:00
|
|
|
def include_tags?
|
|
|
|
SiteSetting.tagging_enabled
|
|
|
|
end
|
2016-06-27 21:01:00 -05:00
|
|
|
|
2016-04-25 14:55:15 -05:00
|
|
|
def tags
|
2016-05-04 13:02:47 -05:00
|
|
|
object.tags.map(&:name)
|
2016-04-25 14:55:15 -05:00
|
|
|
end
|
|
|
|
|
2016-12-05 06:31:43 -06:00
|
|
|
def include_featured_link?
|
|
|
|
SiteSetting.topic_featured_link_enabled
|
|
|
|
end
|
|
|
|
|
|
|
|
def featured_link
|
|
|
|
object.featured_link
|
|
|
|
end
|
|
|
|
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|