diff --git a/framework/core/src/Flarum/Api/Actions/Discussions/Create.php b/framework/core/src/Flarum/Api/Actions/Discussions/Create.php index 2456c10af..716f1d433 100644 --- a/framework/core/src/Flarum/Api/Actions/Discussions/Create.php +++ b/framework/core/src/Flarum/Api/Actions/Discussions/Create.php @@ -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));