-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a notification driver with the new channel extender (#28)
- Loading branch information
Showing
4 changed files
with
92 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?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\Pusher; | ||
|
||
use Flarum\Notification\Blueprint\BlueprintInterface; | ||
use Flarum\Notification\Driver\NotificationDriverInterface; | ||
use Illuminate\Contracts\Queue\Queue; | ||
|
||
class PusherNotificationDriver implements NotificationDriverInterface | ||
{ | ||
/** | ||
* @var Queue | ||
*/ | ||
protected $queue; | ||
|
||
public function __construct(Queue $queue) | ||
{ | ||
$this->queue = $queue; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function send(BlueprintInterface $blueprint, array $users): void | ||
{ | ||
if (count($users)) { | ||
$this->queue->push(new SendPusherNotificationsJob($blueprint, $users)); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function registerType(string $blueprintClass, array $driversEnabledByDefault): void | ||
{ | ||
// ... | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?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\Pusher; | ||
|
||
use Flarum\Notification\Blueprint\BlueprintInterface; | ||
use Flarum\Queue\AbstractJob; | ||
use Flarum\User\User; | ||
use Pusher; | ||
|
||
class SendPusherNotificationsJob extends AbstractJob | ||
{ | ||
/** | ||
* @var BlueprintInterface | ||
*/ | ||
private $blueprint; | ||
|
||
/** | ||
* @var User[] | ||
*/ | ||
private $recipients; | ||
|
||
public function __construct(BlueprintInterface $blueprint, array $recipients) | ||
{ | ||
$this->blueprint = $blueprint; | ||
$this->recipients = $recipients; | ||
} | ||
|
||
public function handle(Pusher $pusher) | ||
{ | ||
foreach ($this->recipients as $user) { | ||
if ($user->shouldAlert($this->blueprint::getType())) { | ||
$pusher->trigger('private-user'.$user->id, 'notification', null); | ||
} | ||
} | ||
} | ||
} |