1
0
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:
Toby Zerner
2015-05-04 12:19:25 +09:30
parent 45ab262547
commit 56ef42f931
6 changed files with 100 additions and 23 deletions

View File

@@ -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.
*