1
0
mirror of https://github.com/flarum/core.git synced 2025-08-07 08:56:38 +02:00

Use new extenders (#25)

This commit is contained in:
Sami Mazouz
2020-12-08 16:59:03 +01:00
committed by GitHub
parent 78288cfbae
commit 99e73a38a9
2 changed files with 25 additions and 74 deletions

View File

@@ -7,6 +7,8 @@
* LICENSE file that was distributed with this source code.
*/
use Flarum\Api\Controller;
use Flarum\Api\Serializer\BasicUserSerializer;
use Flarum\Api\Serializer\PostSerializer;
use Flarum\Extend;
use Flarum\Likes\Event\PostWasLiked;
@@ -33,11 +35,29 @@ return [
(new Extend\Notification())
->type(PostLikedBlueprint::class, PostSerializer::class, ['alert']),
function (Dispatcher $events) {
$events->subscribe(Listener\AddPostLikesRelationship::class);
$events->subscribe(Listener\SaveLikesToDatabase::class);
(new Extend\ApiSerializer(PostSerializer::class))
->hasMany('likes', BasicUserSerializer::class)
->attribute('canLike', function (PostSerializer $serializer, $model) {
return (bool) $serializer->getActor()->can('like', $model);
}),
$events->listen(PostWasLiked::class, Listener\SendNotificationWhenPostIsLiked::class);
$events->listen(PostWasUnliked::class, Listener\SendNotificationWhenPostIsUnliked::class);
(new Extend\ApiController(Controller\ShowDiscussionController::class))
->addInclude('posts.likes'),
(new Extend\ApiController(Controller\ListPostsController::class))
->addInclude('likes'),
(new Extend\ApiController(Controller\ShowPostController::class))
->addInclude('likes'),
(new Extend\ApiController(Controller\CreatePostController::class))
->addInclude('likes'),
(new Extend\ApiController(Controller\UpdatePostController::class))
->addInclude('likes'),
(new Extend\Event())
->listen(PostWasLiked::class, Listener\SendNotificationWhenPostIsLiked::class)
->listen(PostWasUnliked::class, Listener\SendNotificationWhenPostIsUnliked::class),
function (Dispatcher $events) {
$events->subscribe(Listener\SaveLikesToDatabase::class);
},
];