Add API to collect posts that were removed during an action

This is useful for both the Sticky and Categories extensions, where if
you sticky a discussion and then immediately unsticky it, or if you
move it to a category and then immediately move it back, the last
“activity” post will be removed.
This commit is contained in:
Toby Zerner 2015-05-02 08:12:09 +09:30
parent 40715203a5
commit cb5baf8953

View File

@ -49,6 +49,13 @@ class Discussion extends Model
*/
public $addedPosts = [];
/**
* An array of posts that have been removed during this request.
*
* @var \Flarum\Core\Models\Post[]
*/
public $removedPosts = [];
/**
* The user for which the state relationship should be loaded.
*
@ -166,6 +173,18 @@ class Discussion extends Model
$this->addedPosts[] = $post;
}
/**
* Specify that a post was removed from this discussion during this
* request for later retrieval.
*
* @param \Flarum\Core\Models\Post $post
* @return void
*/
public function postWasRemoved(Post $post)
{
$this->removedPosts[] = $post->id;
}
/**
* Define the relationship with the discussion's posts.
*