diff --git a/app/assets/javascripts/discourse/controllers/topic.js.es6 b/app/assets/javascripts/discourse/controllers/topic.js.es6 index f115c5a7520..ddb65adb90c 100644 --- a/app/assets/javascripts/discourse/controllers/topic.js.es6 +++ b/app/assets/javascripts/discourse/controllers/topic.js.es6 @@ -1096,13 +1096,13 @@ export default Ember.Controller.extend(BufferedContent, { } case "deleted": { postStream - .triggerDeletedPost(data.id, data.post_number) + .triggerDeletedPost(data.id) .then(() => refresh({ id: data.id })); break; } case "recovered": { postStream - .triggerRecoveredPost(data.id, data.post_number) + .triggerRecoveredPost(data.id) .then(() => refresh({ id: data.id })); break; } diff --git a/app/assets/javascripts/discourse/models/post-stream.js.es6 b/app/assets/javascripts/discourse/models/post-stream.js.es6 index 66db43c4e9c..64313ab20ef 100644 --- a/app/assets/javascripts/discourse/models/post-stream.js.es6 +++ b/app/assets/javascripts/discourse/models/post-stream.js.es6 @@ -565,8 +565,9 @@ export default RestModel.extend({ return this.triggerChangedPost(postId, new Date()); } else { // need to insert into stream - const url = "/posts/" + postId; + const url = `/posts/${postId}`; const store = this.store; + return ajax(url).then(p => { const post = store.createRecord("post", p); const stream = this.get("stream"); @@ -591,7 +592,9 @@ export default RestModel.extend({ }); if (index < posts.length) { - posts.insertAt(index, post); + this.get("postsWithPlaceholders").refreshAll(() => { + posts.insertAt(index, post); + }); } else { if (post.post_number < posts[posts.length - 1].post_number + 5) { this.appendMore(); diff --git a/test/javascripts/models/post-stream-test.js.es6 b/test/javascripts/models/post-stream-test.js.es6 index c33e9d6d51b..acad4c6c780 100644 --- a/test/javascripts/models/post-stream-test.js.es6 +++ b/test/javascripts/models/post-stream-test.js.es6 @@ -681,6 +681,40 @@ QUnit.test("loadedAllPosts when the id changes", assert => { ); }); +QUnit.test("triggerRecoveredPost", async assert => { + const postStream = buildStream(4567); + const store = postStream.store; + + [1, 2, 3, 5].forEach(id => { + postStream.appendPost( + store.createRecord("post", { id: id, post_number: id }) + ); + }); + + const response = object => { + return [200, { "Content-Type": "application/json" }, object]; + }; + + // prettier-ignore + server.get("/posts/4", () => { // eslint-disable-line no-undef + return response({ id: 4, post_number: 4 }); + }); + + assert.equal( + postStream.get("postsWithPlaceholders.length"), + 4, + "it should return the right length" + ); + + await postStream.triggerRecoveredPost(4); + + assert.equal( + postStream.get("postsWithPlaceholders.length"), + 5, + "it should return the right length" + ); +}); + QUnit.test("comitting and triggerNewPostInStream race condition", assert => { const postStream = buildStream(4964); const store = postStream.store;