From d06ac6c35362d5ac44e131bb9b5b989dc70af499 Mon Sep 17 00:00:00 2001 From: Penar Musaraj Date: Mon, 14 Dec 2020 15:24:36 -0500 Subject: [PATCH] FIX: Show quote replies when filtering (#11483) Only applies when using the `enable_filtered_replies_view` site setting. The filter query was not accounting for quote replies. --- lib/topic_view.rb | 4 +++- spec/requests/topics_controller_spec.rb | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/topic_view.rb b/lib/topic_view.rb index 86f0f0124c1..e88a5057953 100644 --- a/lib/topic_view.rb +++ b/lib/topic_view.rb @@ -773,10 +773,12 @@ class TopicView # Filter replies if @replies_to_post_number.present? + post_id = filtered_post_id(@replies_to_post_number.to_i) @filtered_posts = @filtered_posts.where(' posts.post_number = 1 OR posts.post_number = :post_number - OR posts.reply_to_post_number = :post_number', { post_number: @replies_to_post_number.to_i }) + OR posts.reply_to_post_number = :post_number + OR posts.id IN (SELECT pr.reply_post_id FROM post_replies pr WHERE pr.post_id = :post_id)', { post_number: @replies_to_post_number.to_i, post_id: post_id }) @contains_gaps = true end diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb index 4dc874c3543..ac18ce3550b 100644 --- a/spec/requests/topics_controller_spec.rb +++ b/spec/requests/topics_controller_spec.rb @@ -2127,6 +2127,8 @@ RSpec.describe TopicsController do let!(:post3) { Fabricate(:post, topic: topic, reply_to_post_number: post2.post_number) } let!(:post4) { Fabricate(:post, topic: topic, reply_to_post_number: post2.post_number) } let!(:post5) { Fabricate(:post, topic: topic) } + let!(:quote_reply) { Fabricate(:basic_reply, user: user, topic: topic) } + let!(:post_reply) { PostReply.create(post_id: post2.id, reply_post_id: quote_reply.id) } it 'should return the right posts' do get "/t/#{topic.id}.json", params: { @@ -2141,7 +2143,7 @@ RSpec.describe TopicsController do expect(body.has_key?("related_messages")).to eq(false) ids = body["post_stream"]["posts"].map { |p| p["id"] } - expect(ids).to eq([post.id, post2.id, post3.id, post4.id]) + expect(ids).to eq([post.id, post2.id, post3.id, post4.id, quote_reply.id]) end end