mirror of
https://github.com/flarum/framework.git
synced 2024-11-25 09:41:49 +08:00
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;
|
||||
|
||||
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)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user