mirror of
https://github.com/flarum/core.git
synced 2025-10-10 06:24:26 +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:
@@ -46,6 +46,13 @@ class Discussion extends Model
|
||||
'last_post_number' => 'integer'
|
||||
];
|
||||
|
||||
/**
|
||||
* An array of posts that have been modified during this request.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $modifiedPosts = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be mutated to dates.
|
||||
*
|
||||
@@ -140,7 +147,7 @@ class Discussion extends Model
|
||||
/**
|
||||
* Set the discussion's start post details.
|
||||
*
|
||||
* @param \Flarum\Core\Posts\Post $post
|
||||
* @param Post $post
|
||||
* @return $this
|
||||
*/
|
||||
public function setStartPost(Post $post)
|
||||
@@ -155,7 +162,7 @@ class Discussion extends Model
|
||||
/**
|
||||
* Set the discussion's last post details.
|
||||
*
|
||||
* @param \Flarum\Core\Posts\Post $post
|
||||
* @param Post $post
|
||||
* @return $this
|
||||
*/
|
||||
public function setLastPost(Post $post)
|
||||
@@ -214,16 +221,28 @@ class Discussion extends Model
|
||||
* DiscussionRenamedPost, and delete if the title has been reverted
|
||||
* completely.)
|
||||
*
|
||||
* @param \Flarum\Core\Posts\Post $post The post to save.
|
||||
* @return \Flarum\Core\Posts\Post The resulting post. It may or may not be
|
||||
* the same post as was originally intended to be saved. It also may not
|
||||
* exist, if the merge logic resulted in deletion.
|
||||
* @param MergeablePost $post The post to save.
|
||||
* @return Post The resulting post. It may or may not be the same post as
|
||||
* was originally intended to be saved. It also may not exist, if the
|
||||
* merge logic resulted in deletion.
|
||||
*/
|
||||
public function mergePost(MergeablePost $post)
|
||||
{
|
||||
$lastPost = $this->posts()->latest('time')->first();
|
||||
|
||||
return $post->saveAfter($lastPost);
|
||||
$post = $post->saveAfter($lastPost);
|
||||
|
||||
return $this->modifiedPosts[] = $post;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the posts that have been modified during this request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getModifiedPosts()
|
||||
{
|
||||
return $this->modifiedPosts;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -129,26 +129,6 @@ class CommentPost extends Post
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the relationship with the user who edited the post.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function editUser()
|
||||
{
|
||||
return $this->belongsTo('Flarum\Core\Users\User', 'edit_user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the relationship with the user who hid the post.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function hideUser()
|
||||
{
|
||||
return $this->belongsTo('Flarum\Core\Users\User', 'hide_user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get text formatter instance.
|
||||
*
|
||||
|
@@ -111,6 +111,26 @@ class Post extends Model
|
||||
return $this->belongsTo('Flarum\Core\Users\User', 'user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the relationship with the user who edited the post.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function editUser()
|
||||
{
|
||||
return $this->belongsTo('Flarum\Core\Users\User', 'edit_user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the relationship with the user who hid the post.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function hideUser()
|
||||
{
|
||||
return $this->belongsTo('Flarum\Core\Users\User', 'hide_user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all posts, regardless of their type, by removing the
|
||||
* `RegisteredTypesScope` global scope constraints applied on this model.
|
||||
|
Reference in New Issue
Block a user