diff --git a/lib/post_creator.rb b/lib/post_creator.rb index aa6c75c72bb..62d2c39dd62 100644 --- a/lib/post_creator.rb +++ b/lib/post_creator.rb @@ -114,7 +114,7 @@ class PostCreator User .joins("LEFT JOIN user_options ON user_options.user_id = users.id") - .joins("LEFT JOIN muted_users ON muted_users.muted_user_id = #{@user.id.to_i}") + .joins("LEFT JOIN muted_users ON muted_users.user_id = users.id AND muted_users.muted_user_id = #{@user.id.to_i}") .where("user_options.user_id IS NOT NULL") .where(" (user_options.user_id IN (:user_ids) AND NOT user_options.allow_private_messages) OR diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rb index 2ad2736ab28..20f1e82b53f 100644 --- a/spec/components/post_creator_spec.rb +++ b/spec/components/post_creator_spec.rb @@ -1131,6 +1131,7 @@ describe PostCreator do context "private message to a muted user" do let(:muted_me) { Fabricate(:evil_trout) } + let(:another_user) { Fabricate(:user) } it 'should fail' do updater = UserUpdater.new(muted_me, muted_me) @@ -1141,10 +1142,14 @@ describe PostCreator do title: 'this message is to someone who muted me!', raw: "you will have to see this even if you muted me!", archetype: Archetype.private_message, - target_usernames: "#{muted_me.username}" + target_usernames: "#{muted_me.username},#{another_user.username}" ) + expect(pc).not_to be_valid - expect(pc.errors).to be_present + + expect(pc.errors.full_messages).to contain_exactly( + I18n.t(:not_accepting_pms, username: muted_me.username) + ) end let(:staff_user) { Fabricate(:admin) }