FIX: Do not live-load posts from ignored users

FIX: Do not live-load posts from ignored users

diff --git a/app/assets/javascripts/discourse/models/post-stream.js.es6 b/app/assets/javascripts/discourse/models/post-stream.js.es6
index ed079dc..a426fc2 100644
--- a/app/assets/javascripts/discourse/models/post-stream.js.es6
+++ b/app/assets/javascripts/discourse/models/post-stream.js.es6
@@ -609,7 +609,11 @@ export default RestModel.extend({
         this.set("loadingLastPost", true);
         return this.findPostsByIds([postId])
           .then(posts => {
-            posts.forEach(p => this.appendPost(p));
+            const ignoredUsers = this.get("currentUser.ignored_users");
+            posts.forEach(p => {
+              if (ignoredUsers && ignoredUsers.includes(p.username)) return;
+              this.appendPost(p);
+            });
           })
           .finally(() => {
             this.set("loadingLastPost", false);
diff --git a/test/javascripts/models/post-stream-test.js.es6 b/test/javascripts/models/post-stream-test.js.es6
index 26e4780..c5153f1 100644
--- a/test/javascripts/models/post-stream-test.js.es6
+++ b/test/javascripts/models/post-stream-test.js.es6
@@ -800,6 +800,44 @@ QUnit.test("comitting and triggerNewPostInStream race condition", assert => {
   );
 });
 
+QUnit.test("triggerNewPostInStream for ignored posts", async assert => {
+  const postStream = buildStream(280, [1]);
+  const store = postStream.store;
+  postStream.currentUser = Discourse.User.create({
+    username: "eviltrout",
+    name: "eviltrout",
+    id: 321,
+    ignored_users: ["ignoreduser"]
+  });
+
+  postStream.appendPost(store.createRecord("post", { id: 1, post_number: 1 }));
+
+  const post2 = store.createRecord("post", {
+    id: 101,
+    post_number: 2,
+    username: "regularuser"
+  });
+
+  const post3 = store.createRecord("post", {
+    id: 102,
+    post_number: 3,
+    username: "ignoreduser"
+  });
+
+  var stub = sandbox
+    .stub(postStream, "findPostsByIds")
+    .returns(Promise.resolve([post2]));
+
+  await postStream.triggerNewPostInStream(101);
+  assert.equal(postStream.get("posts.length"), 2, "it added the regular post");
+
+  stub.restore();
+  sandbox.stub(postStream, "findPostsByIds").returns(Promise.resolve([post3]));
+
+  postStream.triggerNewPostInStream(102);
+  assert.equal(postStream.posts.length, 2, "it does not add the ignored post");
+});
+
 QUnit.test("postsWithPlaceholders", assert => {
   const postStream = buildStream(4964, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
   const postsWithPlaceholders = postStream.get("postsWithPlaceholders");

GitHub sha: 000a35b2

1 Like