mirror of
https://github.com/flarum/core.git
synced 2025-08-01 22:20:21 +02:00
Add concept of "mergeable" activity posts
For example: when you rename a discussion, DiscussionRenamedPost is created. If you rename it again immediately afterwards, then a new DiscussionRenamedPost can be merged into the old one. This will either result in the old one being updated with the new title, or it being deleted all together if it was renamed back to the old title.
This commit is contained in:
@@ -185,6 +185,24 @@ class Discussion extends Model
|
||||
$this->removedPosts[] = $post->id;
|
||||
}
|
||||
|
||||
public function addPost(Post $post)
|
||||
{
|
||||
if ($post instanceof MergeableInterface) {
|
||||
$lastPost = $this->posts()->orderBy('time', 'desc')->first();
|
||||
$post = $post->saveAfter($lastPost);
|
||||
} else {
|
||||
$post->save();
|
||||
}
|
||||
|
||||
if ($post->exists) {
|
||||
$this->postWasAdded($post);
|
||||
} else {
|
||||
$this->postWasRemoved($post);
|
||||
}
|
||||
|
||||
return $post->exists;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the relationship with the discussion's posts.
|
||||
*
|
||||
|
Reference in New Issue
Block a user