mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 08:41:25 +08:00
FIX: Hide live-loaded posts from ignored users
This commit is contained in:
@ -609,9 +609,14 @@ export default RestModel.extend({
|
|||||||
this.set("loadingLastPost", true);
|
this.set("loadingLastPost", true);
|
||||||
return this.findPostsByIds([postId])
|
return this.findPostsByIds([postId])
|
||||||
.then(posts => {
|
.then(posts => {
|
||||||
const ignoredUsers = this.get("currentUser.ignored_users");
|
const ignoredUsers =
|
||||||
|
Discourse.User.current() &&
|
||||||
|
Discourse.User.current().get("ignored_users");
|
||||||
posts.forEach(p => {
|
posts.forEach(p => {
|
||||||
if (ignoredUsers && ignoredUsers.includes(p.username)) return;
|
if (ignoredUsers && ignoredUsers.includes(p.username)) {
|
||||||
|
this.stream.removeObject(postId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.appendPost(p);
|
this.appendPost(p);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
@ -803,12 +803,14 @@ QUnit.test("comitting and triggerNewPostInStream race condition", assert => {
|
|||||||
QUnit.test("triggerNewPostInStream for ignored posts", async assert => {
|
QUnit.test("triggerNewPostInStream for ignored posts", async assert => {
|
||||||
const postStream = buildStream(280, [1]);
|
const postStream = buildStream(280, [1]);
|
||||||
const store = postStream.store;
|
const store = postStream.store;
|
||||||
postStream.currentUser = Discourse.User.create({
|
Discourse.User.resetCurrent(
|
||||||
|
Discourse.User.create({
|
||||||
username: "eviltrout",
|
username: "eviltrout",
|
||||||
name: "eviltrout",
|
name: "eviltrout",
|
||||||
id: 321,
|
id: 321,
|
||||||
ignored_users: ["ignoreduser"]
|
ignored_users: ["ignoreduser"]
|
||||||
});
|
})
|
||||||
|
);
|
||||||
|
|
||||||
postStream.appendPost(store.createRecord("post", { id: 1, post_number: 1 }));
|
postStream.appendPost(store.createRecord("post", { id: 1, post_number: 1 }));
|
||||||
|
|
||||||
@ -829,13 +831,31 @@ QUnit.test("triggerNewPostInStream for ignored posts", async assert => {
|
|||||||
.returns(Promise.resolve([post2]));
|
.returns(Promise.resolve([post2]));
|
||||||
|
|
||||||
await postStream.triggerNewPostInStream(101);
|
await postStream.triggerNewPostInStream(101);
|
||||||
assert.equal(postStream.get("posts.length"), 2, "it added the regular post");
|
assert.equal(
|
||||||
|
postStream.posts.length,
|
||||||
|
2,
|
||||||
|
"it added the regular post to the posts"
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
postStream.get("stream.length"),
|
||||||
|
2,
|
||||||
|
"it added the regular post to the stream"
|
||||||
|
);
|
||||||
|
|
||||||
stub.restore();
|
stub.restore();
|
||||||
sandbox.stub(postStream, "findPostsByIds").returns(Promise.resolve([post3]));
|
sandbox.stub(postStream, "findPostsByIds").returns(Promise.resolve([post3]));
|
||||||
|
|
||||||
postStream.triggerNewPostInStream(102);
|
await postStream.triggerNewPostInStream(102);
|
||||||
assert.equal(postStream.posts.length, 2, "it does not add the ignored post");
|
assert.equal(
|
||||||
|
postStream.posts.length,
|
||||||
|
2,
|
||||||
|
"it does not add the ignored post to the posts"
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
postStream.stream.length,
|
||||||
|
2,
|
||||||
|
"it does not add the ignored post to the stream"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test("postsWithPlaceholders", assert => {
|
QUnit.test("postsWithPlaceholders", assert => {
|
||||||
|
Reference in New Issue
Block a user