2015-03-24 12:37:38 +08:00
|
|
|
<?php namespace Flarum\Api\Actions\Notifications;
|
|
|
|
|
|
|
|
use Flarum\Core\Commands\ReadNotificationCommand;
|
2015-05-03 10:34:43 +08:00
|
|
|
use Flarum\Api\Actions\SerializeResourceAction;
|
|
|
|
use Flarum\Api\JsonApiRequest;
|
|
|
|
use Illuminate\Contracts\Bus\Dispatcher;
|
2015-05-27 06:29:31 +08:00
|
|
|
use Tobscure\JsonApi\Document;
|
2015-03-24 12:37:38 +08:00
|
|
|
|
2015-05-03 10:34:43 +08:00
|
|
|
class UpdateAction extends SerializeResourceAction
|
2015-03-24 12:37:38 +08:00
|
|
|
{
|
|
|
|
/**
|
2015-05-03 10:34:43 +08:00
|
|
|
* @var \Illuminate\Contracts\Bus\Dispatcher
|
2015-03-24 12:37:38 +08:00
|
|
|
*/
|
2015-05-03 10:34:43 +08:00
|
|
|
protected $bus;
|
2015-03-24 12:37:38 +08:00
|
|
|
|
2015-05-03 10:34:43 +08:00
|
|
|
/**
|
2015-06-18 10:54:18 +08:00
|
|
|
* @inheritdoc
|
2015-05-03 10:34:43 +08:00
|
|
|
*/
|
|
|
|
public static $serializer = 'Flarum\Api\Serializers\NotificationSerializer';
|
2015-03-24 12:37:38 +08:00
|
|
|
|
2015-06-18 10:54:18 +08:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public static $include = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public static $link = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public static $limitMax = 50;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public static $limit = 20;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public static $sortFields = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public static $sort;
|
|
|
|
|
2015-05-03 10:34:43 +08:00
|
|
|
/**
|
|
|
|
* Instantiate the action.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Contracts\Bus\Dispatcher $bus
|
|
|
|
*/
|
|
|
|
public function __construct(Dispatcher $bus)
|
|
|
|
{
|
|
|
|
$this->bus = $bus;
|
|
|
|
}
|
2015-03-24 12:37:38 +08:00
|
|
|
|
2015-05-03 10:34:43 +08:00
|
|
|
/**
|
|
|
|
* Mark a notification as read, and return it ready to be serialized and
|
|
|
|
* assigned to the JsonApi response.
|
|
|
|
*
|
|
|
|
* @param \Flarum\Api\JsonApiRequest $request
|
2015-05-27 06:29:31 +08:00
|
|
|
* @param \Tobscure\JsonApi\Document $document
|
|
|
|
* @return \Illuminate\Database\Eloquent\Collection
|
2015-05-03 10:34:43 +08:00
|
|
|
*/
|
2015-05-27 06:29:31 +08:00
|
|
|
protected function data(JsonApiRequest $request, Document $document)
|
2015-05-03 10:34:43 +08:00
|
|
|
{
|
|
|
|
return $this->bus->dispatch(
|
|
|
|
new ReadNotificationCommand($request->get('id'), $request->actor->getUser())
|
|
|
|
);
|
2015-03-24 12:37:38 +08:00
|
|
|
}
|
|
|
|
}
|