2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-01-20 12:11:52 +08:00
|
|
|
class UserSummarySerializer < ApplicationSerializer
|
2020-11-17 20:07:16 +08:00
|
|
|
class TopicSerializer < BasicTopicSerializer
|
|
|
|
attributes :category_id, :like_count, :created_at
|
2016-01-20 12:11:52 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
class ReplySerializer < ApplicationSerializer
|
|
|
|
attributes :post_number, :like_count, :created_at
|
|
|
|
has_one :topic, serializer: TopicSerializer
|
|
|
|
end
|
|
|
|
|
2016-04-14 05:02:51 +08:00
|
|
|
class LinkSerializer < ApplicationSerializer
|
2016-04-21 04:58:30 +08:00
|
|
|
attributes :url, :title, :clicks, :post_number
|
|
|
|
has_one :topic, serializer: TopicSerializer
|
|
|
|
|
|
|
|
def post_number
|
|
|
|
object.post.post_number
|
|
|
|
end
|
2016-04-14 05:02:51 +08:00
|
|
|
end
|
|
|
|
|
2019-01-12 02:09:06 +08:00
|
|
|
class UserWithCountSerializer < ApplicationSerializer
|
2021-04-28 03:09:32 +08:00
|
|
|
attributes :id,
|
|
|
|
:username,
|
|
|
|
:name,
|
|
|
|
:count,
|
|
|
|
:avatar_template,
|
|
|
|
:admin,
|
|
|
|
:moderator,
|
|
|
|
:trust_level,
|
2021-07-08 15:46:21 +08:00
|
|
|
:flair_name,
|
|
|
|
:flair_url,
|
|
|
|
:flair_bg_color,
|
|
|
|
:flair_color,
|
2021-04-28 03:09:32 +08:00
|
|
|
:primary_group_name
|
2019-01-12 02:09:06 +08:00
|
|
|
|
2019-01-14 09:30:44 +08:00
|
|
|
def include_name?
|
|
|
|
SiteSetting.enable_names?
|
|
|
|
end
|
|
|
|
|
2019-01-12 02:09:06 +08:00
|
|
|
def avatar_template
|
|
|
|
User.avatar_template(object[:username], object[:uploaded_avatar_id])
|
|
|
|
end
|
2021-04-28 03:09:32 +08:00
|
|
|
|
2021-07-08 15:46:21 +08:00
|
|
|
def flair_name
|
|
|
|
object.flair_group&.name
|
2021-04-28 03:09:32 +08:00
|
|
|
end
|
|
|
|
|
2021-07-08 15:46:21 +08:00
|
|
|
def flair_url
|
|
|
|
object.flair_group&.flair_url
|
2021-04-28 03:09:32 +08:00
|
|
|
end
|
|
|
|
|
2021-07-08 15:46:21 +08:00
|
|
|
def flair_bg_color
|
|
|
|
object.flair_group&.flair_bg_color
|
|
|
|
end
|
|
|
|
|
|
|
|
def flair_color
|
|
|
|
object.flair_group&.flair_color
|
2021-04-28 03:09:32 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def primary_group_name
|
|
|
|
object.primary_group&.name
|
|
|
|
end
|
2016-04-14 05:02:51 +08:00
|
|
|
end
|
|
|
|
|
2018-07-19 04:37:50 +08:00
|
|
|
class CategoryWithCountsSerializer < ApplicationSerializer
|
|
|
|
attributes :topic_count,
|
|
|
|
:post_count,
|
|
|
|
:id,
|
|
|
|
:name,
|
|
|
|
:color,
|
|
|
|
:text_color,
|
|
|
|
:slug,
|
|
|
|
:read_restricted,
|
|
|
|
:parent_category_id
|
|
|
|
end
|
|
|
|
|
2016-01-20 12:11:52 +08:00
|
|
|
has_many :topics, serializer: TopicSerializer
|
|
|
|
has_many :replies, serializer: ReplySerializer, embed: :object
|
2016-04-14 05:02:51 +08:00
|
|
|
has_many :links, serializer: LinkSerializer, embed: :object
|
2016-05-05 04:47:48 +08:00
|
|
|
has_many :most_liked_by_users, serializer: UserWithCountSerializer, embed: :object
|
|
|
|
has_many :most_liked_users, serializer: UserWithCountSerializer, embed: :object
|
|
|
|
has_many :most_replied_to_users, serializer: UserWithCountSerializer, embed: :object
|
2016-04-21 04:58:30 +08:00
|
|
|
has_many :badges, serializer: UserBadgeSerializer, embed: :object
|
2018-07-19 04:37:50 +08:00
|
|
|
has_many :top_categories, serializer: CategoryWithCountsSerializer, embed: :object
|
2016-01-20 12:11:52 +08:00
|
|
|
|
2016-03-31 00:05:16 +08:00
|
|
|
attributes :likes_given,
|
|
|
|
:likes_received,
|
2017-11-18 06:53:22 +08:00
|
|
|
:topics_entered,
|
2016-03-31 00:05:16 +08:00
|
|
|
:posts_read_count,
|
|
|
|
:days_visited,
|
|
|
|
:topic_count,
|
|
|
|
:post_count,
|
2016-04-14 05:02:51 +08:00
|
|
|
:time_read,
|
2017-11-15 05:39:07 +08:00
|
|
|
:recent_time_read,
|
2020-05-15 00:57:35 +08:00
|
|
|
:bookmark_count,
|
2024-02-05 17:00:36 +08:00
|
|
|
:can_see_summary_stats,
|
|
|
|
:can_see_user_actions
|
2020-05-15 00:57:35 +08:00
|
|
|
|
|
|
|
def can_see_summary_stats
|
|
|
|
scope.can_see_summary_stats?(object.user)
|
|
|
|
end
|
2016-03-29 14:11:47 +08:00
|
|
|
|
2024-02-05 17:00:36 +08:00
|
|
|
def can_see_user_actions
|
|
|
|
scope.can_see_user_actions?(object.user, [])
|
|
|
|
end
|
|
|
|
|
2016-03-29 14:11:47 +08:00
|
|
|
def include_badges?
|
|
|
|
SiteSetting.enable_badges
|
|
|
|
end
|
2016-03-31 00:05:16 +08:00
|
|
|
|
2016-05-09 21:51:43 +08:00
|
|
|
def include_bookmark_count?
|
|
|
|
scope.authenticated? && object.user_id == scope.user.id
|
|
|
|
end
|
|
|
|
|
2016-03-31 00:05:16 +08:00
|
|
|
def time_read
|
2017-11-15 05:39:07 +08:00
|
|
|
object.time_read
|
|
|
|
end
|
|
|
|
|
|
|
|
def recent_time_read
|
|
|
|
object.recent_time_read
|
2016-03-31 00:05:16 +08:00
|
|
|
end
|
2020-05-15 00:57:35 +08:00
|
|
|
|
|
|
|
def include_likes_given?
|
|
|
|
can_see_summary_stats
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_likes_received?
|
|
|
|
can_see_summary_stats
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_topics_entered?
|
|
|
|
can_see_summary_stats
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_posts_read_count?
|
|
|
|
can_see_summary_stats
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_days_visited?
|
|
|
|
can_see_summary_stats
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_topic_count?
|
|
|
|
can_see_summary_stats
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_post_count?
|
|
|
|
can_see_summary_stats
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_time_read?
|
|
|
|
can_see_summary_stats
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_recent_time_read?
|
|
|
|
can_see_summary_stats
|
|
|
|
end
|
2016-01-20 12:11:52 +08:00
|
|
|
end
|