mirror of
https://github.com/flarum/core.git
synced 2025-08-07 00:47:00 +02:00
wip
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Flarum\Notification\Driver;
|
||||
|
||||
interface GroupableNotificationDriverInterface extends NotificationDriverInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Implies the delay to wait before sending out notifications to allow blueprintGrouping to happen.
|
||||
*
|
||||
* @todo Enable for v2.0+
|
||||
*/
|
||||
public function blueprintGroupingDelay(): ?\DateInterval;
|
||||
|
||||
public function sendGrouped();
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Flarum\Notification\Job;
|
||||
|
||||
use Flarum\Notification\Blueprint\BlueprintInterface;
|
||||
use Flarum\Notification\Driver\NotificationDriverInterface;
|
||||
use Flarum\Queue\AbstractJob;
|
||||
use Flarum\User\User;
|
||||
use Illuminate\Queue\Middleware\WithoutOverlapping;
|
||||
|
||||
class DelayedBlueprintGroupingJob extends AbstractJob
|
||||
{
|
||||
private BlueprintInterface $blueprint;
|
||||
private NotificationDriverInterface $driver;
|
||||
private User $user;
|
||||
|
||||
public function __construct(BlueprintInterface $blueprint, User $user, NotificationDriverInterface $driver)
|
||||
{
|
||||
$this->blueprint = $blueprint;
|
||||
$this->driver = $driver;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function middleware()
|
||||
{
|
||||
return [
|
||||
(new WithoutOverlapping('delayed-blueprint-grouping:' . $this->user->id))->dontRelease()
|
||||
];
|
||||
}
|
||||
}
|
@@ -10,8 +10,11 @@
|
||||
namespace Flarum\Notification;
|
||||
|
||||
use Flarum\Notification\Blueprint\BlueprintInterface;
|
||||
use Flarum\Notification\Driver\GroupableNotificationDriverInterface;
|
||||
use Flarum\Notification\Driver\NotificationDriverInterface;
|
||||
use Flarum\Notification\Job\DelayedBlueprintGroupingJob;
|
||||
use Flarum\User\User;
|
||||
use Illuminate\Contracts\Queue\Queue;
|
||||
|
||||
/**
|
||||
* The Notification Syncer commits notification blueprints to the database, and
|
||||
@@ -47,6 +50,13 @@ class NotificationSyncer
|
||||
*/
|
||||
protected static $beforeSendingCallbacks = [];
|
||||
|
||||
private Queue $queue;
|
||||
|
||||
public function __construct(Queue $queue)
|
||||
{
|
||||
$this->queue = $queue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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,
|
||||
@@ -107,7 +117,21 @@ class NotificationSyncer
|
||||
// didn't have a record in the database). As both operations can be
|
||||
// intensive on resources (database and mail server), we queue them.
|
||||
foreach (static::getNotificationDrivers() as $driverName => $driver) {
|
||||
$driver->send($blueprint, $newRecipients);
|
||||
if ($driver instanceof GroupableNotificationDriverInterface) {
|
||||
$delay = $driver->blueprintGroupingDelay();
|
||||
|
||||
foreach($newRecipients as $recipient) {
|
||||
$job = new DelayedBlueprintGroupingJob(
|
||||
$blueprint,
|
||||
$recipient,
|
||||
$driver
|
||||
);
|
||||
|
||||
$this->queue->later($delay, $job);
|
||||
}
|
||||
} else {
|
||||
$driver->send($blueprint, $newRecipients);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user