diff --git a/extensions/flags/extend.php b/extensions/flags/extend.php index 11009b95d..d3d76f583 100644 --- a/extensions/flags/extend.php +++ b/extensions/flags/extend.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Flarum\Api\Event\Serializing; +use Flarum\Event\ConfigureModelDates; use Flarum\Extend; use Flarum\Flags\Api\Controller\CreateFlagController; use Flarum\Flags\Api\Controller\DeleteFlagsController; @@ -30,7 +32,9 @@ return [ ->delete('/posts/{id}/flags', 'flags.delete', DeleteFlagsController::class), function (Dispatcher $events) { - $events->subscribe(Listener\AddFlagsApi::class); + $events->listen(ConfigureModelDates::class, Listener\AddFlagsApiDates::class); + $events->listen(Serializing::class, Listener\AddFlagsApiAttributes::class); + $events->subscribe(Listener\AddPostFlagsRelationship::class); }, ]; diff --git a/extensions/flags/src/Listener/AddFlagsApi.php b/extensions/flags/src/Listener/AddFlagsApiAttributes.php similarity index 74% rename from extensions/flags/src/Listener/AddFlagsApi.php rename to extensions/flags/src/Listener/AddFlagsApiAttributes.php index 7d4e896ac..92cd365fe 100755 --- a/extensions/flags/src/Listener/AddFlagsApi.php +++ b/extensions/flags/src/Listener/AddFlagsApiAttributes.php @@ -15,13 +15,11 @@ use Flarum\Api\Event\Serializing; use Flarum\Api\Serializer\CurrentUserSerializer; use Flarum\Api\Serializer\ForumSerializer; use Flarum\Api\Serializer\PostSerializer; -use Flarum\Event\ConfigureModelDates; use Flarum\Flags\Flag; use Flarum\Settings\SettingsRepositoryInterface; use Flarum\User\User; -use Illuminate\Contracts\Events\Dispatcher; -class AddFlagsApi +class AddFlagsApiAttributes { /** * @var SettingsRepositoryInterface @@ -36,29 +34,7 @@ class AddFlagsApi $this->settings = $settings; } - /** - * @param Dispatcher $events - */ - public function subscribe(Dispatcher $events) - { - $events->listen(ConfigureModelDates::class, [$this, 'configureModelDates']); - $events->listen(Serializing::class, [$this, 'prepareApiAttributes']); - } - - /** - * @param ConfigureModelDates $event - */ - public function configureModelDates(ConfigureModelDates $event) - { - if ($event->isModel(User::class)) { - $event->dates[] = 'read_flags_at'; - } - } - - /** - * @param Serializing $event - */ - public function prepareApiAttributes(Serializing $event) + public function handle(Serializing $event) { if ($event->isSerializer(ForumSerializer::class)) { $event->attributes['canViewFlags'] = $event->actor->hasPermissionLike('discussion.viewFlags'); diff --git a/extensions/flags/src/Listener/AddFlagsApiDates.php b/extensions/flags/src/Listener/AddFlagsApiDates.php new file mode 100755 index 000000000..f12720e20 --- /dev/null +++ b/extensions/flags/src/Listener/AddFlagsApiDates.php @@ -0,0 +1,25 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Flags\Listener; + +use Flarum\Event\ConfigureModelDates; +use Flarum\User\User; + +class AddFlagsApiDates +{ + public function handle(ConfigureModelDates $event) + { + if ($event->isModel(User::class)) { + $event->dates[] = 'read_flags_at'; + } + } +}