diff --git a/extensions/suspend/extend.php b/extensions/suspend/extend.php index 487bcb3ea..e66ff1566 100644 --- a/extensions/suspend/extend.php +++ b/extensions/suspend/extend.php @@ -9,9 +9,16 @@ * file that was distributed with this source code. */ +use Flarum\Api\Serializer\BasicUserSerializer; +use Flarum\Event\ConfigureNotificationTypes; use Flarum\Extend; use Flarum\Suspend\Access; +use Flarum\Suspend\Event\Suspended; +use Flarum\Suspend\Event\Unsuspended; use Flarum\Suspend\Listener; +use Flarum\Suspend\Notification\UserSuspendedBlueprint; +use Flarum\Suspend\Notification\UserUnsuspendedBlueprint; +use Flarum\User\Event\Saving; use Illuminate\Contracts\Events\Dispatcher; return [ @@ -26,8 +33,15 @@ return [ function (Dispatcher $events) { $events->subscribe(Listener\AddUserSuspendAttributes::class); $events->subscribe(Listener\RevokeAccessFromSuspendedUsers::class); - $events->subscribe(Listener\SaveSuspensionToDatabase::class); - $events->subscribe(Listener\SendNotificationWhenUserIsSuspended::class); + + $events->listen(Saving::class, Listener\SaveSuspensionToDatabase::class); + + $events->listen(ConfigureNotificationTypes::class, function (ConfigureNotificationTypes $event) { + $event->add(UserSuspendedBlueprint::class, BasicUserSerializer::class, ['alert', 'email']); + $event->add(UserUnsuspendedBlueprint::class, BasicUserSerializer::class, ['alert', 'email']); + }); + $events->listen(Suspended::class, Listener\SendNotificationWhenUserIsSuspended::class); + $events->listen(Unsuspended::class, Listener\SendNotificationWhenUserIsUnsuspended::class); $events->subscribe(Access\UserPolicy::class); } diff --git a/extensions/suspend/src/Listener/SaveSuspensionToDatabase.php b/extensions/suspend/src/Listener/SaveSuspensionToDatabase.php index b2ab469ad..e1b3c9ccd 100755 --- a/extensions/suspend/src/Listener/SaveSuspensionToDatabase.php +++ b/extensions/suspend/src/Listener/SaveSuspensionToDatabase.php @@ -29,6 +29,7 @@ class SaveSuspensionToDatabase * @var SuspendValidator */ protected $validator; + /** * @var Dispatcher */ @@ -44,18 +45,7 @@ class SaveSuspensionToDatabase $this->events = $events; } - /** - * @param Dispatcher $events - */ - public function subscribe(Dispatcher $events) - { - $events->listen(Saving::class, [$this, 'whenSavingUser']); - } - - /** - * @param Saving $event - */ - public function whenSavingUser(Saving $event) + public function handle(Saving $event) { $attributes = array_get($event->data, 'attributes', []); diff --git a/extensions/suspend/src/Listener/SendNotificationWhenUserIsSuspended.php b/extensions/suspend/src/Listener/SendNotificationWhenUserIsSuspended.php index b73fbe4dd..e91492848 100644 --- a/extensions/suspend/src/Listener/SendNotificationWhenUserIsSuspended.php +++ b/extensions/suspend/src/Listener/SendNotificationWhenUserIsSuspended.php @@ -11,14 +11,9 @@ namespace Flarum\Suspend\Listener; -use Flarum\Api\Serializer\BasicUserSerializer; -use Flarum\Event\ConfigureNotificationTypes; use Flarum\Notification\NotificationSyncer; use Flarum\Suspend\Event\Suspended; -use Flarum\Suspend\Event\Unsuspended; use Flarum\Suspend\Notification\UserSuspendedBlueprint; -use Flarum\Suspend\Notification\UserUnsuspendedBlueprint; -use Illuminate\Contracts\Events\Dispatcher; class SendNotificationWhenUserIsSuspended { @@ -35,44 +30,11 @@ class SendNotificationWhenUserIsSuspended $this->notifications = $notifications; } - /** - * @param Dispatcher $events - */ - public function subscribe(Dispatcher $events) - { - $events->listen(ConfigureNotificationTypes::class, [$this, 'registerNotificationType']); - $events->listen(Suspended::class, [$this, 'whenSuspended']); - $events->listen(Unsuspended::class, [$this, 'whenUnsuspended']); - } - - /** - * @param ConfigureNotificationTypes $event - */ - public function registerNotificationType(ConfigureNotificationTypes $event) - { - $event->add(UserSuspendedBlueprint::class, BasicUserSerializer::class, ['alert', 'email']); - $event->add(UserUnsuspendedBlueprint::class, BasicUserSerializer::class, ['alert', 'email']); - } - - /** - * @param Suspended $event - */ - public function whenSuspended(Suspended $event) + public function handle(Suspended $event) { $this->notifications->sync( new UserSuspendedBlueprint($event->user, $event->actor), [$event->user] ); } - - /** - * @param Unsuspended $event - */ - public function whenUnsuspended(Unsuspended $event) - { - $this->notifications->sync( - new UserUnsuspendedBlueprint($event->user, $event->actor), - [$event->user] - ); - } } diff --git a/extensions/suspend/src/Listener/SendNotificationWhenUserIsUnsuspended.php b/extensions/suspend/src/Listener/SendNotificationWhenUserIsUnsuspended.php new file mode 100644 index 000000000..3fc3169e4 --- /dev/null +++ b/extensions/suspend/src/Listener/SendNotificationWhenUserIsUnsuspended.php @@ -0,0 +1,40 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Suspend\Listener; + +use Flarum\Notification\NotificationSyncer; +use Flarum\Suspend\Event\Unsuspended; +use Flarum\Suspend\Notification\UserUnsuspendedBlueprint; + +class SendNotificationWhenUserIsUnsuspended +{ + /** + * @var NotificationSyncer + */ + protected $notifications; + + /** + * @param NotificationSyncer $notifications + */ + public function __construct(NotificationSyncer $notifications) + { + $this->notifications = $notifications; + } + + public function handle(Unsuspended $event) + { + $this->notifications->sync( + new UserUnsuspendedBlueprint($event->user, $event->actor), + [$event->user] + ); + } +}