Sync the discussion model/post stream when posts are added/removed

This commit is contained in:
Toby Zerner 2015-05-29 18:56:29 +09:30
parent 026e6361e5
commit 2ef2457c57
2 changed files with 21 additions and 1 deletions

View File

@ -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());
}
}

View File

@ -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()) {