mirror of
https://github.com/discourse/discourse.git
synced 2026-08-06 12:09:27 +08:00
With this change, a user who is ignoring another no longer sees that user's likes or reactions: the ignored user is hidden from the likes/reactions lists, and the like and reaction counts shown to the ignoring user are adjusted accordingly. Anonymous viewers and viewers who aren't ignoring anyone see the original counts. See it in action in the video: https://github.com/user-attachments/assets/535e9aaa-0a1c-49eb-a2d4-5fdebf9d7539
78 lines
2.3 KiB
Ruby
Vendored
78 lines
2.3 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
class PostActionUsersController < ApplicationController
|
|
INDEX_LIMIT = 200
|
|
|
|
def index
|
|
params.require(:post_action_type_id)
|
|
params.require(:id)
|
|
post_action_type_id = params[:post_action_type_id].to_i
|
|
|
|
page = params[:page].to_i
|
|
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.find_by(id: params[:id].to_i)
|
|
guardian.ensure_can_see!(post)
|
|
|
|
post_actions =
|
|
filter_ignored_users(post.post_actions.where(post_action_type_id: post_action_type_id))
|
|
filtered_total = post_actions.count if current_user&.ignored_user_ids&.any?
|
|
|
|
post_actions =
|
|
post_actions
|
|
.includes(:user)
|
|
.offset(page * page_size)
|
|
.order("post_actions.created_at ASC")
|
|
.limit(page_size)
|
|
|
|
post_actions =
|
|
DiscoursePluginRegistry.apply_modifier(:post_action_users_list, post_actions, post)
|
|
|
|
can_see_actors = guardian.can_see_post_actors?(post.topic, post_action_type_id)
|
|
|
|
if !can_see_actors
|
|
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 = filtered_total || post["#{action_type}_count"].to_i
|
|
post_actions = post_actions.to_a
|
|
data = {
|
|
post_action_users:
|
|
serialize_data(
|
|
post_actions,
|
|
PostActionUserSerializer,
|
|
unknown_user_ids: current_user_muting_or_ignoring_users(post_actions.map(&:user_id)),
|
|
),
|
|
}
|
|
|
|
data[:total_rows_post_action_users] = total_count if can_see_actors && total_count > page_size
|
|
|
|
render_json_dump(data)
|
|
end
|
|
|
|
private
|
|
|
|
def filter_ignored_users(scope)
|
|
return scope if current_user.blank?
|
|
|
|
scope.where(<<~SQL, current_user_id: current_user.id)
|
|
NOT EXISTS (
|
|
SELECT 1 FROM ignored_users ig
|
|
WHERE ig.user_id = :current_user_id
|
|
AND ig.ignored_user_id = post_actions.user_id
|
|
AND ig.ignored_user_id <> :current_user_id
|
|
)
|
|
SQL
|
|
end
|
|
|
|
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_ignoring_or_muting_users
|
|
end
|
|
end
|