diff --git a/framework/core/src/Notification/Command/ReadAllNotificationsHandler.php b/framework/core/src/Notification/Command/ReadAllNotificationsHandler.php index d1230ab95..e5914dfb7 100644 --- a/framework/core/src/Notification/Command/ReadAllNotificationsHandler.php +++ b/framework/core/src/Notification/Command/ReadAllNotificationsHandler.php @@ -9,7 +9,10 @@ namespace Flarum\Notification\Command; +use Flarum\Notification\Event\ReadAll; use Flarum\Notification\NotificationRepository; +use Illuminate\Contracts\Events\Dispatcher; +use Illuminate\Support\Carbon; class ReadAllNotificationsHandler { @@ -19,11 +22,18 @@ class ReadAllNotificationsHandler protected $notifications; /** - * @param NotificationRepository $notifications + * @var Dispatcher */ - public function __construct(NotificationRepository $notifications) + protected $events; + + /** + * @param NotificationRepository $notifications + * @param Dispatcher $events + */ + public function __construct(NotificationRepository $notifications, Dispatcher $events) { $this->notifications = $notifications; + $this->events = $events; } /** @@ -37,5 +47,7 @@ class ReadAllNotificationsHandler $actor->assertRegistered(); $this->notifications->markAllAsRead($actor); + + $this->events->dispatch(new ReadAll($actor, Carbon::now())); } } diff --git a/framework/core/src/Notification/Command/ReadNotificationHandler.php b/framework/core/src/Notification/Command/ReadNotificationHandler.php index 514f755ac..a39a4784f 100644 --- a/framework/core/src/Notification/Command/ReadNotificationHandler.php +++ b/framework/core/src/Notification/Command/ReadNotificationHandler.php @@ -10,10 +10,25 @@ namespace Flarum\Notification\Command; use Carbon\Carbon; +use Flarum\Notification\Event\Read; use Flarum\Notification\Notification; +use Illuminate\Contracts\Events\Dispatcher; class ReadNotificationHandler { + /** + * @var Dispatcher + */ + protected $events; + + /** + * @param Dispatcher $events + */ + public function __construct(Dispatcher $events) + { + $this->events = $events; + } + /** * @param ReadNotification $command * @return \Flarum\Notification\Notification @@ -36,6 +51,8 @@ class ReadNotificationHandler $notification->read_at = Carbon::now(); + $this->events->dispatch(new Read($actor, $notification, Carbon::now())); + return $notification; } } diff --git a/framework/core/src/Notification/Event/Read.php b/framework/core/src/Notification/Event/Read.php new file mode 100644 index 000000000..eb0510f59 --- /dev/null +++ b/framework/core/src/Notification/Event/Read.php @@ -0,0 +1,39 @@ +user = $user; + $this->notification = $notification; + $this->timestamp = $timestamp; + } +} diff --git a/framework/core/src/Notification/Event/ReadAll.php b/framework/core/src/Notification/Event/ReadAll.php new file mode 100644 index 000000000..e2bfa72fe --- /dev/null +++ b/framework/core/src/Notification/Event/ReadAll.php @@ -0,0 +1,32 @@ +user = $user; + $this->timestamp = $timestamp; + } +}