1
0
mirror of https://github.com/flarum/core.git synced 2025-08-13 11:54:32 +02:00

Compare commits

...

2 Commits

Author SHA1 Message Date
StyleCI Bot
d5bcc7fcbd Apply fixes from StyleCI 2022-06-15 13:23:08 +00:00
Daniël Klabbers
6be8d3dd17 wip 2022-06-07 21:20:56 +02:00
3 changed files with 88 additions and 1 deletions

View File

@@ -0,0 +1,22 @@
<?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\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();
}

View File

@@ -0,0 +1,41 @@
<?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\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()
];
}
}

View File

@@ -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);
}
}
}