mirror of
https://github.com/flarum/core.git
synced 2025-10-13 07:54:25 +02:00
Add Notification extender beforeSending method (#2533)
This commit is contained in:
@@ -43,6 +43,11 @@ class NotificationSyncer
|
||||
*/
|
||||
protected static $notificationDrivers = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $beforeSendingCallbacks = [];
|
||||
|
||||
/**
|
||||
* Sync a notification so that it is visible to the specified users, and not
|
||||
* visible to anyone else. If it is being made visible for the first time,
|
||||
@@ -94,6 +99,10 @@ class NotificationSyncer
|
||||
$this->setDeleted($toUndelete, false);
|
||||
}
|
||||
|
||||
foreach (static::$beforeSendingCallbacks as $callback) {
|
||||
$newRecipients = $callback($blueprint, $newRecipients);
|
||||
}
|
||||
|
||||
// Create a notification record, and send an email, for all users
|
||||
// receiving this notification for the first time (we know because they
|
||||
// didn't have a record in the database). As both operations can be
|
||||
@@ -176,4 +185,12 @@ class NotificationSyncer
|
||||
{
|
||||
return static::$notificationDrivers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable|string $callback
|
||||
*/
|
||||
public static function beforeSending($callback): void
|
||||
{
|
||||
static::$beforeSendingCallbacks[] = $callback;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user