mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 09:48:18 +08:00
Top level replies (#16087)
* DEV: Show only top level replies Adds a new query param to the topic view so that we can filter out posts that aren't top level replies. If a post is a reply to another post instead of the original topic post we should not include it in the response if the `filter_top_level_replies` query param is present. * add rspec test
This commit is contained in:
@ -2428,6 +2428,29 @@ RSpec.describe TopicsController do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'filter by top level replies' do
|
||||
fab!(:post3) { Fabricate(:post, user: post_author3, topic: topic, reply_to_post_number: post2.post_number) }
|
||||
fab!(:post4) { Fabricate(:post, user: post_author4, topic: topic, reply_to_post_number: post2.post_number) }
|
||||
fab!(:post5) { Fabricate(:post, user: post_author5, topic: topic) }
|
||||
fab!(:post6) { Fabricate(:post, user: post_author4, topic: topic, reply_to_post_number: post5.post_number) }
|
||||
|
||||
it 'should return the right posts' do
|
||||
get "/t/#{topic.id}.json", params: {
|
||||
filter_top_level_replies: true
|
||||
}
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
body = response.parsed_body
|
||||
|
||||
expect(body.has_key?("suggested_topics")).to eq(false)
|
||||
expect(body.has_key?("related_messages")).to eq(false)
|
||||
|
||||
ids = body["post_stream"]["posts"].map { |p| p["id"] }
|
||||
expect(ids).to eq([post2.id, post5.id])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'filter upwards by post id' do
|
||||
fab!(:post3) { Fabricate(:post, user: post_author3, topic: topic) }
|
||||
fab!(:post4) { Fabricate(:post, user: post_author4, topic: topic, reply_to_post_number: post3.post_number) }
|
||||
|
Reference in New Issue
Block a user