mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 00:32:52 +08:00
FIX: Do not live-load posts from ignored users
This commit is contained in:
@ -609,7 +609,11 @@ export default RestModel.extend({
|
|||||||
this.set("loadingLastPost", true);
|
this.set("loadingLastPost", true);
|
||||||
return this.findPostsByIds([postId])
|
return this.findPostsByIds([postId])
|
||||||
.then(posts => {
|
.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(() => {
|
.finally(() => {
|
||||||
this.set("loadingLastPost", false);
|
this.set("loadingLastPost", false);
|
||||||
|
@ -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 => {
|
QUnit.test("postsWithPlaceholders", assert => {
|
||||||
const postStream = buildStream(4964, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
const postStream = buildStream(4964, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
||||||
const postsWithPlaceholders = postStream.get("postsWithPlaceholders");
|
const postsWithPlaceholders = postStream.get("postsWithPlaceholders");
|
||||||
|
Reference in New Issue
Block a user