API for syncing added/removed posts after a discussion is updated

This commit is contained in:
Toby Zerner 2015-05-04 12:17:26 +09:30
parent ed191ca7e4
commit 0d9a3283db
2 changed files with 14 additions and 2 deletions

View File

@ -131,6 +131,18 @@ export default class PostStream {
});
}
sync() {
var discussion = this.discussion;
var addedPosts = discussion.addedPosts();
addedPosts && addedPosts.forEach(this.addPostToEnd.bind(this));
discussion.pushData({links: {addedPosts: null}});
var removedPosts = discussion.removedPosts();
removedPosts && removedPosts.forEach(this.removePost.bind(this));
discussion.pushData({removedPosts: null});
}
makeItem(start, end, post) {
var item = {start, end}
if (post) {

View File

@ -78,8 +78,8 @@ class Discussion extends Model {
var title = prompt('Enter a new title for this discussion:', currentTitle);
if (title && title !== currentTitle) {
this.save({title}).then(discussion => {
if (app.current.discussion && app.current.discussion().id() === discussion.id()) {
discussion.addedPosts().forEach(post => app.current.stream().addPostToEnd(post));
if (app.current instanceof DiscussionPage) {
app.current.stream().sync();
}
m.redraw();
});