diff --git a/app/models/reviewable_flagged_post.rb b/app/models/reviewable_flagged_post.rb index be98034fb56..4ea646aea72 100644 --- a/app/models/reviewable_flagged_post.rb +++ b/app/models/reviewable_flagged_post.rb @@ -243,12 +243,16 @@ protected trigger_spam = false actions.each do |action| - action.agreed_at = Time.zone.now - action.agreed_by_id = performed_by.id - # so callback is called - action.save - action.add_moderator_post_if_needed(performed_by, :agreed, args[:post_was_deleted]) - trigger_spam = true if action.post_action_type_id == PostActionType.types[:spam] + ActiveRecord::Base.transaction do + action.agreed_at = Time.zone.now + action.agreed_by_id = performed_by.id + # so callback is called + action.save + DB.after_commit do + action.add_moderator_post_if_needed(performed_by, :agreed, args[:post_was_deleted]) + trigger_spam = true if action.post_action_type_id == PostActionType.types[:spam] + end + end end DiscourseEvent.trigger(:confirmed_spam_post, post) if trigger_spam diff --git a/lib/topic_query.rb b/lib/topic_query.rb index b004583ef1a..e7950d4b660 100644 --- a/lib/topic_query.rb +++ b/lib/topic_query.rb @@ -312,7 +312,7 @@ class TopicQuery list = private_messages_for(user, :user) list = not_archived(list, user) - .where('NOT (topics.participant_count = 1 AND topics.user_id = ?)', user.id) + .where('NOT (topics.participant_count = 1 AND topics.user_id = ? AND topics.moderator_posts_count = 0)', user.id) create_list(:private_messages, {}, list) end diff --git a/spec/components/topic_query_spec.rb b/spec/components/topic_query_spec.rb index c41e87ba6f8..31138e6c318 100644 --- a/spec/components/topic_query_spec.rb +++ b/spec/components/topic_query_spec.rb @@ -1070,4 +1070,16 @@ describe TopicQuery do end end end + + describe '#list_private_messages' do + it "includes topics with moderator posts" do + private_message_topic = Fabricate(:private_message_post, user: user).topic + + expect(TopicQuery.new(user).list_private_messages(user).topics).to be_empty + + private_message_topic.add_moderator_post(admin, "Thank you for your flag") + + expect(TopicQuery.new(user).list_private_messages(user).topics).to eq([private_message_topic]) + end + end end