From 9f3d6a9a1fc21a4720338c1eded2a12853d9f299 Mon Sep 17 00:00:00 2001 From: David Sevilla Martin Date: Sat, 5 Oct 2019 16:16:41 -0400 Subject: [PATCH] Queue 'new post' notification Fixes flarum/core#1869 --- .../src/Job/SendReplyNotification.php | 53 +++++++++++++++++++ .../SendNotificationWhenReplyIsPosted.php | 29 +++------- 2 files changed, 61 insertions(+), 21 deletions(-) create mode 100644 extensions/subscriptions/src/Job/SendReplyNotification.php diff --git a/extensions/subscriptions/src/Job/SendReplyNotification.php b/extensions/subscriptions/src/Job/SendReplyNotification.php new file mode 100644 index 000000000..f3defb76c --- /dev/null +++ b/extensions/subscriptions/src/Job/SendReplyNotification.php @@ -0,0 +1,53 @@ +post = $post; + $this->lastPostNumber = $lastPostNumber; + } + + public function handle(NotificationSyncer $notifications) { + $post = $this->post; + $discussion = $post->discussion; + + $notify = $discussion->readers() + ->where('users.id', '!=', $post->user_id) + ->where('discussion_user.subscription', 'follow') + ->where('discussion_user.last_read_post_number', $this->lastPostNumber) + ->get(); + + $notifications->sync( + new NewPostBlueprint($post), + $notify->all() + ); + } +} diff --git a/extensions/subscriptions/src/Listener/SendNotificationWhenReplyIsPosted.php b/extensions/subscriptions/src/Listener/SendNotificationWhenReplyIsPosted.php index 1b9754134..b7d7b5a52 100755 --- a/extensions/subscriptions/src/Listener/SendNotificationWhenReplyIsPosted.php +++ b/extensions/subscriptions/src/Listener/SendNotificationWhenReplyIsPosted.php @@ -9,39 +9,26 @@ namespace Flarum\Subscriptions\Listener; -use Flarum\Notification\NotificationSyncer; use Flarum\Post\Event\Posted; -use Flarum\Subscriptions\Notification\NewPostBlueprint; +use Flarum\Subscriptions\Job\SendReplyNotification; +use Illuminate\Contracts\Queue\Queue; class SendNotificationWhenReplyIsPosted { /** - * @var NotificationSyncer + * @var Queue */ - protected $notifications; + protected $queue; - /** - * @param NotificationSyncer $notifications - */ - public function __construct(NotificationSyncer $notifications) + public function __construct(Queue $queue) { - $this->notifications = $notifications; + $this->queue = $queue; } public function handle(Posted $event) { - $post = $event->post; - $discussion = $post->discussion; - - $notify = $discussion->readers() - ->where('users.id', '!=', $post->user_id) - ->where('discussion_user.subscription', 'follow') - ->where('discussion_user.last_read_post_number', $discussion->last_post_number) - ->get(); - - $this->notifications->sync( - new NewPostBlueprint($event->post), - $notify->all() + $this->queue->push( + new SendReplyNotification($event->post, $event->post->discussion->last_post_number) ); } }