mirror of
https://github.com/flarum/framework.git
synced 2024-11-28 20:16:08 +08:00
feat: Add events for Notification read / read all (#3203)
This commit is contained in:
parent
fbfc80f979
commit
77264be5e3
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user