discourse/app/serializers/topic_list_item_serializer.rb

63 lines
1.5 KiB
Ruby
Raw Normal View History

require_dependency 'pinned_check'
class TopicListItemSerializer < ListableTopicSerializer
2013-02-05 14:16:51 -05:00
2013-02-25 11:42:20 -05:00
attributes :views,
:like_count,
:visible,
:pinned,
:closed,
:archived,
:starred,
:has_best_of,
2013-04-02 16:52:51 -04:00
:archetype,
:rank_details
2013-02-05 14:16:51 -05:00
has_one :category
has_many :posters, serializer: TopicPosterSerializer, embed: :objects
def starred
object.user_data.starred?
end
alias :include_starred? :seen
2013-04-02 16:52:51 -04: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?
return false unless object.topic_list.present?
return false unless scope.user.present?
return false unless scope.user.admin?
object.topic_list.filter == :hot
end
2013-02-05 14:16:51 -05:00
def posters
object.posters || []
end
def pinned
PinnedCheck.new(object, object.user_data).pinned?
end
2013-04-02 16:52:51 -04:00
2013-02-05 14:16:51 -05:00
end