mirror of
https://github.com/flarum/core.git
synced 2025-07-17 14:51:19 +02:00
feat: Add events for Notification read / read all (#3203)
This commit is contained in:
@@ -9,7 +9,10 @@
|
|||||||
|
|
||||||
namespace Flarum\Notification\Command;
|
namespace Flarum\Notification\Command;
|
||||||
|
|
||||||
|
use Flarum\Notification\Event\ReadAll;
|
||||||
use Flarum\Notification\NotificationRepository;
|
use Flarum\Notification\NotificationRepository;
|
||||||
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
|
||||||
class ReadAllNotificationsHandler
|
class ReadAllNotificationsHandler
|
||||||
{
|
{
|
||||||
@@ -19,11 +22,18 @@ class ReadAllNotificationsHandler
|
|||||||
protected $notifications;
|
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->notifications = $notifications;
|
||||||
|
$this->events = $events;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,5 +47,7 @@ class ReadAllNotificationsHandler
|
|||||||
$actor->assertRegistered();
|
$actor->assertRegistered();
|
||||||
|
|
||||||
$this->notifications->markAllAsRead($actor);
|
$this->notifications->markAllAsRead($actor);
|
||||||
|
|
||||||
|
$this->events->dispatch(new ReadAll($actor, Carbon::now()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,10 +10,25 @@
|
|||||||
namespace Flarum\Notification\Command;
|
namespace Flarum\Notification\Command;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Flarum\Notification\Event\Read;
|
||||||
use Flarum\Notification\Notification;
|
use Flarum\Notification\Notification;
|
||||||
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
|
|
||||||
class ReadNotificationHandler
|
class ReadNotificationHandler
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var Dispatcher
|
||||||
|
*/
|
||||||
|
protected $events;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Dispatcher $events
|
||||||
|
*/
|
||||||
|
public function __construct(Dispatcher $events)
|
||||||
|
{
|
||||||
|
$this->events = $events;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ReadNotification $command
|
* @param ReadNotification $command
|
||||||
* @return \Flarum\Notification\Notification
|
* @return \Flarum\Notification\Notification
|
||||||
@@ -36,6 +51,8 @@ class ReadNotificationHandler
|
|||||||
|
|
||||||
$notification->read_at = Carbon::now();
|
$notification->read_at = Carbon::now();
|
||||||
|
|
||||||
|
$this->events->dispatch(new Read($actor, $notification, Carbon::now()));
|
||||||
|
|
||||||
return $notification;
|
return $notification;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
39
framework/core/src/Notification/Event/Read.php
Normal file
39
framework/core/src/Notification/Event/Read.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Flarum\Notification\Event;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
use Flarum\Notification\Notification;
|
||||||
|
use Flarum\User\User;
|
||||||
|
|
||||||
|
class Read
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var User
|
||||||
|
*/
|
||||||
|
public $actor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Notification
|
||||||
|
*/
|
||||||
|
public $notification;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var DateTime
|
||||||
|
*/
|
||||||
|
public $timestamp;
|
||||||
|
|
||||||
|
public function __construct(User $user, Notification $notification, DateTime $timestamp)
|
||||||
|
{
|
||||||
|
$this->user = $user;
|
||||||
|
$this->notification = $notification;
|
||||||
|
$this->timestamp = $timestamp;
|
||||||
|
}
|
||||||
|
}
|
32
framework/core/src/Notification/Event/ReadAll.php
Normal file
32
framework/core/src/Notification/Event/ReadAll.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Flarum\Notification\Event;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
use Flarum\User\User;
|
||||||
|
|
||||||
|
class ReadAll
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var User
|
||||||
|
*/
|
||||||
|
public $actor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var DateTime
|
||||||
|
*/
|
||||||
|
public $timestamp;
|
||||||
|
|
||||||
|
public function __construct(User $user, DateTime $timestamp)
|
||||||
|
{
|
||||||
|
$this->user = $user;
|
||||||
|
$this->timestamp = $timestamp;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user