mirror of
https://github.com/flarum/core.git
synced 2025-08-12 11:24:30 +02:00
committed by
Daniël Klabbers
parent
82978c57ce
commit
9f3d6a9a1f
53
extensions/subscriptions/src/Job/SendReplyNotification.php
Normal file
53
extensions/subscriptions/src/Job/SendReplyNotification.php
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Flarum\Subscriptions\Job;
|
||||||
|
|
||||||
|
|
||||||
|
use Flarum\Notification\NotificationSyncer;
|
||||||
|
use Flarum\Post\Post;
|
||||||
|
use Flarum\Subscriptions\Notification\NewPostBlueprint;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class SendReplyNotification implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Queueable, SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Post
|
||||||
|
*/
|
||||||
|
protected $post;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $lastPostNumber;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Post $post
|
||||||
|
* @param int|null $lastPostNumber
|
||||||
|
*/
|
||||||
|
public function __construct(Post $post, $lastPostNumber)
|
||||||
|
{
|
||||||
|
$this->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()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@@ -9,39 +9,26 @@
|
|||||||
|
|
||||||
namespace Flarum\Subscriptions\Listener;
|
namespace Flarum\Subscriptions\Listener;
|
||||||
|
|
||||||
use Flarum\Notification\NotificationSyncer;
|
|
||||||
use Flarum\Post\Event\Posted;
|
use Flarum\Post\Event\Posted;
|
||||||
use Flarum\Subscriptions\Notification\NewPostBlueprint;
|
use Flarum\Subscriptions\Job\SendReplyNotification;
|
||||||
|
use Illuminate\Contracts\Queue\Queue;
|
||||||
|
|
||||||
class SendNotificationWhenReplyIsPosted
|
class SendNotificationWhenReplyIsPosted
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var NotificationSyncer
|
* @var Queue
|
||||||
*/
|
*/
|
||||||
protected $notifications;
|
protected $queue;
|
||||||
|
|
||||||
/**
|
public function __construct(Queue $queue)
|
||||||
* @param NotificationSyncer $notifications
|
|
||||||
*/
|
|
||||||
public function __construct(NotificationSyncer $notifications)
|
|
||||||
{
|
{
|
||||||
$this->notifications = $notifications;
|
$this->queue = $queue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handle(Posted $event)
|
public function handle(Posted $event)
|
||||||
{
|
{
|
||||||
$post = $event->post;
|
$this->queue->push(
|
||||||
$discussion = $post->discussion;
|
new SendReplyNotification($event->post, $event->post->discussion->last_post_number)
|
||||||
|
|
||||||
$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()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user