mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 20:43:19 +08:00
a76d864c51
Note that we don't have a database table and a model for post mentions yet, and I decided to implement it without adding one to avoid heavy data migrations. Still, we may want to add such a model later, that would be convenient, we have such a model for mentions in chat. Note that status appears on all mentions on all posts in a topic except of the case when you just posted a new post, and it appeared on the bottom of the topic. On such posts, status won't be shown immediately for now (you'll need to reload the page to see the status). I'll take care of it in one of the following PRs.
66 lines
1.1 KiB
Ruby
66 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class WebHookPostSerializer < PostSerializer
|
|
|
|
attributes :topic_posts_count,
|
|
:topic_filtered_posts_count,
|
|
:topic_archetype,
|
|
:category_slug
|
|
|
|
def include_topic_title?
|
|
true
|
|
end
|
|
|
|
def include_raw?
|
|
true
|
|
end
|
|
|
|
def include_category_id?
|
|
true
|
|
end
|
|
|
|
%i{
|
|
can_view
|
|
can_edit
|
|
can_delete
|
|
can_recover
|
|
can_wiki
|
|
actions_summary
|
|
can_view_edit_history
|
|
yours
|
|
flair_url
|
|
flair_bg_color
|
|
flair_color
|
|
notice
|
|
mentioned_users
|
|
}.each do |attr|
|
|
define_method("include_#{attr}?") do
|
|
false
|
|
end
|
|
end
|
|
|
|
def topic_posts_count
|
|
object.topic ? object.topic.posts_count : 0
|
|
end
|
|
|
|
def topic_filtered_posts_count
|
|
object.topic ? object.topic.posts.where(post_type: Post.types[:regular]).count : 0
|
|
end
|
|
|
|
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
|
|
|
|
def include_readers_count?
|
|
false
|
|
end
|
|
end
|