A platform for community discussion. Free, open, simple.
FIX: double selecting replies (#17086)
Ghassan Maslamani84b0a6414d15
diff --git a/app/assets/javascripts/discourse/app/controllers/topic.js b/app/assets/javascripts/discourse/app/controllers/topic.jsindex 3832df9372a..2e28cca50f1 100644--- a/app/assets/javascripts/discourse/app/controllers/topic.js+++ b/app/assets/javascripts/discourse/app/controllers/topic.js@@ -890,7 +890,8 @@ export default Controller.extend(bufferedProperty("model"), {selectReplies(post) {ajax(`/posts/${post.id}/reply-ids.json`).then((replies) => {const replyIds = replies.map((r) => r.id);- this.selectedPostIds.pushObjects([post.id, ...replyIds]);+ const postIds = [...this.selectedPostIds, post.id, ...replyIds];+ this.set("selectedPostIds", [...new Set(postIds)]);this._forceRefreshPostStream();});},diff --git a/app/assets/javascripts/discourse/tests/unit/controllers/topic-test.js b/app/assets/javascripts/discourse/tests/unit/controllers/topic-test.jsindex e7b66504a9d..de0517afb08 100644--- a/app/assets/javascripts/discourse/tests/unit/controllers/topic-test.js+++ b/app/assets/javascripts/discourse/tests/unit/controllers/topic-test.js@@ -599,6 +599,52 @@ discourseModule("Unit | Controller | topic", function (hooks) {);});+ test("selectReplies", async function (assert) {+ pretender.get("/posts/1/reply-ids.json", () => {+ return [+ 200,+ { "Content-Type": "application/json" },+ [{ id: 2, level: 1 }],+ ];+ });++ let model = topicWithStream({+ posts: [{ id: 1 }, { id: 2 }],+ });++ const controller = this.getController("topic", { model });++ controller.send("selectReplies", { id: 1 });+ await settled();++ assert.strictEqual(+ controller.get("selectedPostsCount"),+ 2,+ "It should select two, the post and its replies"+ );++ controller.send("togglePostSelection", { id: 1 });+ assert.strictEqual(+ controller.get("selectedPostsCount"),+ 1,+ "It should be selecting one only "+ );+ assert.strictEqual(+ controller.get("selectedPostIds")[0],+ 2,+ "It should be selecting the reply id "+ );++ controller.send("selectReplies", { id: 1 });+ await settled();++ assert.strictEqual(+ controller.get("selectedPostsCount"),+ 2,+ "It should be selecting two, even if reply was already selected"+ );+ });+test("topVisibleChanged", function (assert) {let model = topicWithStream({posts: [{ id: 1 }],