FIX: Change UserCommScreener to use user_ids (#17489)

It makes more sense to use user_ids for the UserCommScreener
introduced in fa5f3e228c102d4b9f7c6dde6eb07ef1f5880bbd since
in most cases the ID will be available, not the username. This
was discovered while starting work on a plugin that will
use this. In the cases where only usernames are available
the extra query is negligble.
This commit is contained in:
Martin Brennan
2022-07-14 15:23:09 +10:00
committed by GitHub
parent b20dcec7d9
commit 6b2ea1b47b
5 changed files with 71 additions and 66 deletions

View File

@ -113,8 +113,9 @@ class PostCreator
# Make sure none of the users have muted or ignored the creator or prevented
# PMs from being sent to them
UserCommScreener.new(acting_user: @user, target_usernames: names).preventing_actor_communication.each do |username|
errors.add(:base, I18n.t(:not_accepting_pms, username: username))
target_users = User.where(username_lower: names.map(&:downcase)).pluck(:id, :username).to_h
UserCommScreener.new(acting_user: @user, target_user_ids: target_users.keys).preventing_actor_communication.each do |user_id|
errors.add(:base, I18n.t(:not_accepting_pms, username: target_users[user_id]))
end
return false if errors[:base].present?