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,
|
|
|
|
:has_best_of,
|
2013-04-03 04:52:51 +08:00
|
|
|
:archetype,
|
2013-09-20 04:25:25 +08:00
|
|
|
:rank_details,
|
|
|
|
:last_poster_username
|
2013-02-06 03:16:51 +08:00
|
|
|
|
2013-05-13 09:07:02 +08:00
|
|
|
has_one :category, serializer: BasicCategorySerializer
|
2013-02-06 03:16:51 +08:00
|
|
|
has_many :posters, serializer: TopicPosterSerializer, embed: :objects
|
|
|
|
|
|
|
|
def starred
|
|
|
|
object.user_data.starred?
|
|
|
|
end
|
|
|
|
alias :include_starred? :seen
|
|
|
|
|
2013-04-03 04:52:51 +08:00
|
|
|
|
|
|
|
# This is for debugging / tweaking the hot topic rankings.
|
|
|
|
# We will likely remove it after we are happier with things.
|
|
|
|
def rank_details
|
|
|
|
|
|
|
|
hot_topic_type = case object.hot_topic.hot_topic_type
|
|
|
|
when 1 then 'sticky'
|
|
|
|
when 2 then 'recent high scoring'
|
|
|
|
when 3 then 'old high scoring'
|
|
|
|
end
|
|
|
|
|
|
|
|
{topic_score: object.score,
|
|
|
|
percent_rank: object.percent_rank,
|
|
|
|
random_bias: object.hot_topic.random_bias,
|
|
|
|
random_multiplier: object.hot_topic.random_multiplier,
|
|
|
|
days_ago_bias: object.hot_topic.days_ago_bias,
|
|
|
|
days_ago_multiplier: object.hot_topic.days_ago_multiplier,
|
|
|
|
ranking_score: object.hot_topic.score,
|
|
|
|
hot_topic_type: hot_topic_type}
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_rank_details?
|
2013-04-04 03:24:26 +08:00
|
|
|
object.topic_list.try(:has_rank_details?)
|
2013-04-03 04:52:51 +08:00
|
|
|
end
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
def posters
|
|
|
|
object.posters || []
|
|
|
|
end
|
|
|
|
|
2013-09-20 04:25:25 +08:00
|
|
|
def last_poster_username
|
|
|
|
object.posters.find { |poster| poster.user.id == object.last_post_user_id }.try(:user).try(:username)
|
|
|
|
end
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|