mirror of
https://github.com/flarum/framework.git
synced 2024-12-12 06:03:39 +08:00
Sync the discussion model/post stream when posts are added/removed
This commit is contained in:
parent
026e6361e5
commit
2ef2457c57
|
@ -23,8 +23,9 @@ export default function(app) {
|
||||||
|
|
||||||
function deleteAction() {
|
function deleteAction() {
|
||||||
this.delete();
|
this.delete();
|
||||||
|
this.discussion().pushData({removedPosts: [this.id()]});
|
||||||
if (app.current instanceof DiscussionPage) {
|
if (app.current instanceof DiscussionPage) {
|
||||||
app.current.stream().removePost(this.id());
|
app.current.stream.removePost(this.id());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,25 @@ import computed from 'flarum/utils/computed';
|
||||||
import ItemList from 'flarum/utils/item-list';
|
import ItemList from 'flarum/utils/item-list';
|
||||||
|
|
||||||
class Discussion extends Model {
|
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() {
|
unreadCount() {
|
||||||
var user = app.session.user();
|
var user = app.session.user();
|
||||||
if (user && user.readTime() < this.lastTime()) {
|
if (user && user.readTime() < this.lastTime()) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user