2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-12-23 00:08:35 +08:00
|
|
|
class WebHookPostSerializer < PostSerializer
|
2019-10-02 09:41:33 +08:00
|
|
|
attributes :topic_posts_count, :topic_filtered_posts_count, :topic_archetype, :category_slug
|
2018-01-18 02:40:21 +08:00
|
|
|
|
2017-04-21 10:04:21 +08:00
|
|
|
def include_topic_title?
|
|
|
|
true
|
2016-12-23 00:08:35 +08:00
|
|
|
end
|
|
|
|
|
2020-06-11 01:55:03 +08:00
|
|
|
def include_raw?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2020-09-02 22:42:51 +08:00
|
|
|
def include_category_id?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2017-04-21 10:04:21 +08:00
|
|
|
%i[
|
|
|
|
can_view
|
|
|
|
can_edit
|
|
|
|
can_delete
|
|
|
|
can_recover
|
2023-06-01 11:32:05 +08:00
|
|
|
can_see_hidden_post
|
2017-04-21 10:04:21 +08:00
|
|
|
can_wiki
|
2018-05-21 10:52:57 +08:00
|
|
|
actions_summary
|
|
|
|
can_view_edit_history
|
|
|
|
yours
|
2021-07-08 15:46:21 +08:00
|
|
|
flair_url
|
|
|
|
flair_bg_color
|
|
|
|
flair_color
|
2020-11-11 20:49:53 +08:00
|
|
|
notice
|
2022-12-06 23:10:36 +08:00
|
|
|
mentioned_users
|
2024-12-03 10:43:27 +08:00
|
|
|
badges_granted
|
2017-04-21 10:04:21 +08:00
|
|
|
].each { |attr| define_method("include_#{attr}?") { false } }
|
2018-01-18 02:40:21 +08:00
|
|
|
|
2024-11-28 03:36:51 +08:00
|
|
|
def topic_posts
|
|
|
|
@topic_posts ||= object.topic.posts.where(user_deleted: false)
|
|
|
|
end
|
|
|
|
|
2018-01-18 02:40:21 +08:00
|
|
|
def topic_posts_count
|
2024-11-28 03:36:51 +08:00
|
|
|
object.topic ? topic_posts.count : 0
|
2018-01-18 02:40:21 +08:00
|
|
|
end
|
|
|
|
|
2019-12-05 01:22:44 +08:00
|
|
|
def topic_filtered_posts_count
|
2024-11-28 03:36:51 +08:00
|
|
|
object.topic ? topic_posts.where(post_type: Post.types[:regular]).count : 0
|
2019-12-05 01:22:44 +08:00
|
|
|
end
|
|
|
|
|
2019-10-02 09:41:33 +08:00
|
|
|
def topic_archetype
|
|
|
|
object.topic ? object.topic.archetype : ""
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_category_slug?
|
|
|
|
object.topic && object.topic.category
|
|
|
|
end
|
|
|
|
|
|
|
|
def category_slug
|
|
|
|
object.topic && object.topic.category ? object.topic.category.slug_for_url : ""
|
|
|
|
end
|
|
|
|
|
2019-08-27 20:09:00 +08:00
|
|
|
def include_readers_count?
|
|
|
|
false
|
|
|
|
end
|
2016-12-23 00:08:35 +08:00
|
|
|
end
|