-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
ReadNotificationHandler.php
58 lines (46 loc) · 1.37 KB
/
ReadNotificationHandler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?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\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
* @throws \Flarum\User\Exception\PermissionDeniedException
*/
public function handle(ReadNotification $command)
{
$actor = $command->actor;
$actor->assertRegistered();
$notification = Notification::where('user_id', $actor->id)->findOrFail($command->notificationId);
Notification::where([
'user_id' => $actor->id,
'type' => $notification->type,
'subject_id' => $notification->subject_id
])
->update(['read_at' => Carbon::now()]);
$notification->read_at = Carbon::now();
$this->events->dispatch(new Read($actor, $notification, Carbon::now()));
return $notification;
}
}