diff --git a/framework/core/js/forum/src/initializers/post-controls.js b/framework/core/js/forum/src/initializers/post-controls.js index 384df6ecc..dfa378235 100644 --- a/framework/core/js/forum/src/initializers/post-controls.js +++ b/framework/core/js/forum/src/initializers/post-controls.js @@ -23,8 +23,9 @@ export default function(app) { function deleteAction() { this.delete(); + this.discussion().pushData({removedPosts: [this.id()]}); if (app.current instanceof DiscussionPage) { - app.current.stream().removePost(this.id()); + app.current.stream.removePost(this.id()); } } diff --git a/framework/core/js/lib/models/discussion.js b/framework/core/js/lib/models/discussion.js index f0d533f45..ed2cdbeaf 100644 --- a/framework/core/js/lib/models/discussion.js +++ b/framework/core/js/lib/models/discussion.js @@ -3,6 +3,25 @@ import computed from 'flarum/utils/computed'; import ItemList from 'flarum/utils/item-list'; class Discussion extends Model { + pushData(newData) { + super.pushData(newData); + + var posts = this.data().links.posts; + if (posts) { + if (newData.removedPosts) { + posts.linkage.forEach((linkage, i) => { + if (newData.removedPosts.indexOf(linkage.id) !== -1) { + posts.linkage.splice(i, 1); + } + }); + } + + if (newData.links && newData.links.addedPosts) { + [].push.apply(posts.linkage, newData.links.addedPosts.linkage); + } + } + } + unreadCount() { var user = app.session.user(); if (user && user.readTime() < this.lastTime()) {