A platform for community discussion. Free, open, simple.
FIX: Don't return post replies from other topics
Robin Wardf83362b05b11
diff --git a/app/models/post.rb b/app/models/post.rbindex 96027645d10..44368e538a0 100644--- a/app/models/post.rb+++ b/app/models/post.rb@@ -819,9 +819,11 @@ class Post < ActiveRecord::BaseUNIONSELECT reply_post_id, level + 1FROM post_replies AS r+ JOIN posts AS p ON p.id = reply_post_idJOIN breadcrumb AS b ON (r.post_id = b.id)WHERE r.post_id <> r.reply_post_id- AND b.level < :max_reply_level+ AND b.level < :max_reply_level+ AND p.topic_id = :topic_id), breadcrumb_with_count AS (SELECTid,@@ -844,7 +846,7 @@ class Post < ActiveRecord::Base# for example it skips a post when it contains 2 quotes (which are replies) from different postsbuilder.where("count = 1") if only_replies_to_single_post- replies = builder.query_hash(post_id: id, max_reply_level: MAX_REPLY_LEVEL)+ replies = builder.query_hash(post_id: id, max_reply_level: MAX_REPLY_LEVEL, topic_id: topic_id)replies.each { |r| r.symbolize_keys! }secured_ids = Post.secured(guardian).where(id: replies.map { |r| r[:id] }).pluck(:id).to_setdiff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rbindex 804ee527ade..a97b2d561b2 100644--- a/spec/models/post_spec.rb+++ b/spec/models/post_spec.rb@@ -951,6 +951,11 @@ describe Post doexpect(p6.reply_ids).to be_empty # quotes itselfend+ it "ignores posts moved to other topics" do+ p2.update_column(:topic_id, Fabricate(:topic).id)+ expect(p1.reply_ids).to be_blank+ end+it "does not skip any replies" doexpect(p1.reply_ids(only_replies_to_single_post: false)).to eq([{ id: p2.id, level: 1 }, { id: p4.id, level: 2 }, { id: p5.id, level: 3 }, { id: p6.id, level: 2 }])expect(p2.reply_ids(only_replies_to_single_post: false)).to eq([{ id: p4.id, level: 1 }, { id: p5.id, level: 2 }, { id: p6.id, level: 1 }])