mirror of
https://github.com/flarum/core.git
synced 2025-10-09 05:56:25 +02:00
- Use contextual namespaces within Flarum\Core - Clean up and docblock everything - Refactor Activity/Notification blueprint stuff - Refactor Formatter stuff - Refactor Search stuff - Upgrade to JSON-API 1.0 - Removed “addedPosts” and “removedPosts” relationships from discussion API. This was used for adding/removing event posts after renaming a discussion etc. Instead we should make an additional request to get all new posts Todo: - Fix Extenders and extensions - Get rid of repository interfaces - Fix other bugs I’ve inevitably introduced
95 lines
2.0 KiB
PHP
95 lines
2.0 KiB
PHP
<?php namespace Flarum\Api\Actions\Discussions;
|
|
|
|
use Flarum\Core\Discussions\Commands\StartDiscussion;
|
|
use Flarum\Core\Discussions\Commands\ReadDiscussion;
|
|
use Flarum\Api\Actions\CreateAction as BaseCreateAction;
|
|
use Flarum\Api\JsonApiRequest;
|
|
use Illuminate\Contracts\Bus\Dispatcher;
|
|
|
|
class CreateAction extends BaseCreateAction
|
|
{
|
|
/**
|
|
* The command bus.
|
|
*
|
|
* @var Dispatcher
|
|
*/
|
|
protected $bus;
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public static $serializer = 'Flarum\Api\Serializers\DiscussionSerializer';
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public static $include = [
|
|
'posts' => true,
|
|
'startUser' => true,
|
|
'lastUser' => true,
|
|
'startPost' => true,
|
|
'lastPost' => true
|
|
];
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public static $link = [];
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public static $limitMax = 50;
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public static $limit = 20;
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public static $sortFields = [];
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public static $sort;
|
|
|
|
/**
|
|
* Instantiate the action.
|
|
*
|
|
* @param Dispatcher $bus
|
|
*/
|
|
public function __construct(Dispatcher $bus)
|
|
{
|
|
$this->bus = $bus;
|
|
}
|
|
|
|
/**
|
|
* Create a discussion according to input from the API request.
|
|
*
|
|
* @param JsonApiRequest $request
|
|
* @return \Flarum\Core\Discussions\Discussion
|
|
*/
|
|
protected function create(JsonApiRequest $request)
|
|
{
|
|
$actor = $request->actor;
|
|
|
|
$discussion = $this->bus->dispatch(
|
|
new StartDiscussion($actor, $request->get('data'))
|
|
);
|
|
|
|
// 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 ($actor->exists) {
|
|
$this->bus->dispatch(
|
|
new ReadDiscussion($discussion->id, $actor, 1)
|
|
);
|
|
}
|
|
|
|
return $discussion;
|
|
}
|
|
}
|