diff --git a/framework/core/src/Flarum/Api/Actions/Posts/Create.php b/framework/core/src/Flarum/Api/Actions/Posts/Create.php index f1c3943be..81a63951d 100644 --- a/framework/core/src/Flarum/Api/Actions/Posts/Create.php +++ b/framework/core/src/Flarum/Api/Actions/Posts/Create.php @@ -2,6 +2,7 @@ use Event; use Flarum\Core\Posts\Commands\PostReplyCommand; +use Flarum\Core\Discussions\Commands\ReadDiscussionCommand; use Flarum\Core\Users\User; use Flarum\Api\Actions\Base; use Flarum\Api\Serializers\PostSerializer; @@ -15,6 +16,8 @@ class Create extends Base */ protected function run() { + $user = User::current(); + // We've received a request to post a reply. By default, the only // required attributes of a post is the ID of the discussion to post in, // the post content, and the author's user account. Let's set up a @@ -22,12 +25,20 @@ class Create extends Base // to add data to the command. $discussionId = $this->input('posts.links.discussion'); $content = $this->input('posts.content'); - $command = new PostReplyCommand($discussionId, $content, User::current()); + $command = new PostReplyCommand($discussionId, $content, $user); Event::fire('Flarum.Api.Actions.Posts.Create.WillExecuteCommand', [$command]); $post = $this->commandBus->execute($command); + // After replying, 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($discussionId, $user, $post->number); + $this->commandBus->execute($command); + } + // Presumably, the post was created successfully. (The command handler // would have thrown an exception if not.) We set this post as our // document's primary element.