From 446eb40bb6ba45a4a65eff9a673f6b1731a488cb Mon Sep 17 00:00:00 2001 From: Bianca Nenciu Date: Mon, 29 Aug 2022 15:52:54 +0300 Subject: [PATCH] FIX: Do not invite whisper or small action posters (#18123) If a topic is converted to a private message, all posters were invited to the new private message. This included users who only whispered or posted small actions. --- app/models/topic_converter.rb | 4 +++- spec/models/topic_converter_spec.rb | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/models/topic_converter.rb b/app/models/topic_converter.rb index 21645753106..47c8b4a3c72 100644 --- a/app/models/topic_converter.rb +++ b/app/models/topic_converter.rb @@ -63,7 +63,9 @@ class TopicConverter private def posters - @posters ||= @topic.posts.distinct.pluck(:user_id) + @posters ||= @topic.posts + .where.not(post_type: [Post.types[:small_action], Post.types[:whisper]]) + .distinct.pluck(:user_id) end def increment_users_post_count diff --git a/spec/models/topic_converter_spec.rb b/spec/models/topic_converter_spec.rb index 084d50f0d19..d66b1cd045a 100644 --- a/spec/models/topic_converter_spec.rb +++ b/spec/models/topic_converter_spec.rb @@ -169,6 +169,17 @@ RSpec.describe TopicConverter do expect(topic_user.reload.notification_level).to eq(TopicUser.notification_levels[:watching]) end + it "invites only users with regular posts" do + post2 = Fabricate(:post, topic: topic) + whipser_post = Fabricate(:post, topic: topic, post_type: Post.types[:whisper]) + small_action_post = Fabricate(:post, topic: topic, post_type: Post.types[:small_action]) + + topic.convert_to_private_message(admin) + + expect(topic.reload.topic_allowed_users.pluck(:user_id)) + .to contain_exactly(admin.id, post.user_id, post2.user_id) + end + it "changes user_action type" do Jobs.run_immediately! UserActionManager.enable