1
0
mirror of https://github.com/flarum/core.git synced 2025-10-12 07:24:27 +02:00

Improve post stream

- Return all discussion post IDs from API requests which add/remove
posts, so the post stream updates appropriately. Related to #146
- Always unload posts that are two pages away, no matter how fast
you’re scrolling
- Retrieve posts from cache instead of reloading them
- Fix various bugs. Maybe #152, needs confirmation
This commit is contained in:
Toby Zerner
2015-07-06 16:26:27 +09:30
parent 746df7e3ad
commit 5fe88e448e
11 changed files with 93 additions and 128 deletions

View File

@@ -2,7 +2,6 @@ import ItemList from 'flarum/utils/item-list';
import ComposerBody from 'flarum/components/composer-body';
import Alert from 'flarum/components/alert';
import ActionButton from 'flarum/components/action-button';
import Composer from 'flarum/components/composer';
import icon from 'flarum/helpers/icon';
export default class ReplyComposer extends ComposerBody {
@@ -44,26 +43,11 @@ export default class ReplyComposer extends ComposerBody {
var data = this.data();
app.store.createRecord('posts').save(data).then((post) => {
app.composer.hide();
discussion.pushAttributes({
relationships: {
lastUser: post.user(),
lastPost: post
},
lastTime: post.time(),
lastPostNumber: post.number(),
commentsCount: discussion.commentsCount() + 1,
readTime: post.time(),
readNumber: post.number()
});
discussion.data().relationships.posts.data.push({type: 'posts', id: post.id()});
app.store.createRecord('posts').save(data).then(post => {
// If we're currently viewing the discussion which this reply was made
// in, then we can add the post to the end of the post stream.
if (app.current && app.current.discussion && app.current.discussion().id() === discussion.id()) {
app.current.stream.pushPost(post);
if (app.viewingDiscussion(discussion)) {
app.current.stream.update();
m.route(app.route('discussion.near', {
id: discussion.id(),
slug: discussion.slug(),
@@ -89,6 +73,8 @@ export default class ReplyComposer extends ComposerBody {
})
);
}
app.composer.hide();
}, errors => {
this.loading(false);
m.redraw();