mirror of
https://github.com/flarum/core.git
synced 2025-05-14 11:25:22 +02:00
Add NotificationWillBeSent event
This commit is contained in:
parent
1153e41b7a
commit
351775ef02
16
src/Core/Events/NotificationWillBeSent.php
Normal file
16
src/Core/Events/NotificationWillBeSent.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php namespace Flarum\Core\Events;
|
||||||
|
|
||||||
|
use Flarum\Core\Notifications\NotificationInterface;
|
||||||
|
|
||||||
|
class NotificationWillBeSent
|
||||||
|
{
|
||||||
|
public $notification;
|
||||||
|
|
||||||
|
public $users;
|
||||||
|
|
||||||
|
public function __construct(NotificationInterface $notification, array &$users)
|
||||||
|
{
|
||||||
|
$this->notification = $notification;
|
||||||
|
$this->users = $users;
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use Flarum\Core\Repositories\NotificationRepositoryInterface;
|
use Flarum\Core\Repositories\NotificationRepositoryInterface;
|
||||||
use Flarum\Core\Models\Notification;
|
use Flarum\Core\Models\Notification;
|
||||||
|
use Flarum\Core\Events\NotificationWillBeSent;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Closure;
|
use Closure;
|
||||||
|
|
||||||
@ -66,6 +67,8 @@ class NotificationSyncer
|
|||||||
if (count($newRecipients)) {
|
if (count($newRecipients)) {
|
||||||
$now = Carbon::now('utc')->toDateTimeString();
|
$now = Carbon::now('utc')->toDateTimeString();
|
||||||
|
|
||||||
|
event(new NotificationWillBeSent($notification, $newRecipients));
|
||||||
|
|
||||||
Notification::insert(
|
Notification::insert(
|
||||||
array_map(function ($user) use ($attributes, $notification, $now) {
|
array_map(function ($user) use ($attributes, $notification, $now) {
|
||||||
return $attributes + ['user_id' => $user->id, 'time' => $now];
|
return $attributes + ['user_id' => $user->id, 'time' => $now];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user