mirror of
https://github.com/discourse/discourse.git
synced 2025-06-01 05:53:52 +08:00
DEV: Add post_action_users_list modifier for PostActionUsersController (#25740)
This commit adds another plugin modifier related to post actions, similar to ae24e04a5ed1921908c8cf1926245fed40aee562. This will be used to exclude users who liked _and_ reacted to the post, since now in discourse-reactions we make a Like when a user reacts too. This will affect the display of the post footer.
This commit is contained in:
@ -12,19 +12,9 @@ class PostActionUsersController < ApplicationController
|
||||
page_size = fetch_limit_from_params(default: INDEX_LIMIT, max: INDEX_LIMIT)
|
||||
|
||||
# Find the post, and then determine if they can see the post (if deleted)
|
||||
post = Post.with_deleted.where(id: params[:id].to_i).first
|
||||
post = Post.with_deleted.find_by(id: params[:id].to_i)
|
||||
guardian.ensure_can_see!(post)
|
||||
|
||||
unknown_user_ids = Set.new
|
||||
if current_user.present?
|
||||
result = DB.query_single(<<~SQL, user_id: current_user.id)
|
||||
SELECT mu.muted_user_id AS id FROM muted_users AS mu WHERE mu.user_id = :user_id
|
||||
UNION
|
||||
SELECT iu.ignored_user_id AS id FROM ignored_users AS iu WHERE iu.user_id = :user_id
|
||||
SQL
|
||||
unknown_user_ids.merge(result)
|
||||
end
|
||||
|
||||
post_actions =
|
||||
post
|
||||
.post_actions
|
||||
@ -34,20 +24,23 @@ class PostActionUsersController < ApplicationController
|
||||
.order("post_actions.created_at ASC")
|
||||
.limit(page_size)
|
||||
|
||||
post_actions =
|
||||
DiscoursePluginRegistry.apply_modifier(:post_action_users_list, post_actions, post)
|
||||
|
||||
if !guardian.can_see_post_actors?(post.topic, post_action_type_id)
|
||||
raise Discourse::InvalidAccess unless current_user
|
||||
raise Discourse::InvalidAccess if current_user.blank?
|
||||
post_actions = post_actions.where(user_id: current_user.id)
|
||||
end
|
||||
|
||||
action_type = PostActionType.types.key(post_action_type_id)
|
||||
total_count = post["#{action_type}_count"].to_i
|
||||
|
||||
post_actions = post_actions.to_a
|
||||
data = {
|
||||
post_action_users:
|
||||
serialize_data(
|
||||
post_actions.to_a,
|
||||
post_actions,
|
||||
PostActionUserSerializer,
|
||||
unknown_user_ids: unknown_user_ids,
|
||||
unknown_user_ids: current_user_muting_or_ignoring_users(post_actions.map(&:user_id)),
|
||||
),
|
||||
}
|
||||
|
||||
@ -55,4 +48,14 @@ class PostActionUsersController < ApplicationController
|
||||
|
||||
render_json_dump(data)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def current_user_muting_or_ignoring_users(user_ids)
|
||||
return [] if current_user.blank?
|
||||
UserCommScreener.new(
|
||||
acting_user: current_user,
|
||||
target_user_ids: user_ids,
|
||||
).actor_preventing_communication
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user