mirror of
https://github.com/flarum/framework.git
synced 2024-11-23 06:55:13 +08:00
Mark a discussion as read when it is created
This commit is contained in:
parent
b0f6d7f1f8
commit
72485d534e
|
@ -3,6 +3,7 @@
|
|||
use Event;
|
||||
|
||||
use Flarum\Core\Discussions\Commands\StartDiscussionCommand;
|
||||
use Flarum\Core\Discussions\Commands\ReadDiscussionCommand;
|
||||
use Flarum\Core\Users\User;
|
||||
use Flarum\Api\Actions\Base;
|
||||
use Flarum\Api\Serializers\DiscussionSerializer;
|
||||
|
@ -21,12 +22,21 @@ class Create extends Base
|
|||
// and pass them through to the StartDiscussionCommand.
|
||||
$title = $this->input('discussions.title');
|
||||
$content = $this->input('discussions.content');
|
||||
$command = new StartDiscussionCommand($title, $content, User::current());
|
||||
$user = User::current();
|
||||
$command = new StartDiscussionCommand($title, $content, $user);
|
||||
|
||||
Event::fire('Flarum.Api.Actions.Discussions.Create.WillExecuteCommand', [$command, $this->document]);
|
||||
|
||||
$discussion = $this->commandBus->execute($command);
|
||||
|
||||
// After creating the discussion, we assume that the user has seen all
|
||||
// of the posts in the discussion; thus, we will mark the discussion
|
||||
// as read if they are logged in.
|
||||
if ($user->exists) {
|
||||
$command = new ReadDiscussionCommand($discussion->id, $user, 1);
|
||||
$this->commandBus->execute($command);
|
||||
}
|
||||
|
||||
$serializer = new DiscussionSerializer(['posts']);
|
||||
$this->document->setPrimaryElement($serializer->resource($discussion));
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user