mirror of
https://github.com/flarum/core.git
synced 2025-07-30 21:20:24 +02:00
Update for new notifications API
This commit is contained in:
@@ -1,38 +1,29 @@
|
||||
<?php namespace Flarum\Sticky;
|
||||
|
||||
use Flarum\Core\Models\User;
|
||||
use Flarum\Core\Models\Discussion;
|
||||
use Flarum\Core\Notifications\Types\Notification;
|
||||
use Flarum\Core\Notifications\Types\AlertableNotification;
|
||||
use Flarum\Core\Notifications\NotificationAbstract;
|
||||
|
||||
class DiscussionStickiedNotification extends Notification implements AlertableNotification
|
||||
class DiscussionStickiedNotification extends NotificationAbstract
|
||||
{
|
||||
protected $discussion;
|
||||
|
||||
protected $sender;
|
||||
|
||||
protected $post;
|
||||
|
||||
public function __construct(Discussion $discussion, User $sender, DiscussionStickiedPost $post = null)
|
||||
public function __construct(DiscussionStickiedPost $post)
|
||||
{
|
||||
$this->discussion = $discussion;
|
||||
$this->sender = $sender;
|
||||
$this->post = $post;
|
||||
}
|
||||
|
||||
public function getSubject()
|
||||
{
|
||||
return $this->discussion;
|
||||
return $this->post->discussion;
|
||||
}
|
||||
|
||||
public function getSender()
|
||||
{
|
||||
return $this->sender;
|
||||
return $this->post->user;
|
||||
}
|
||||
|
||||
public function getAlertData()
|
||||
public function getData()
|
||||
{
|
||||
return ['postNumber' => $this->post->number];
|
||||
return ['postNumber' => (int) $this->post->number];
|
||||
}
|
||||
|
||||
public static function getType()
|
||||
|
@@ -4,16 +4,18 @@ use Flarum\Sticky\DiscussionStickiedPost;
|
||||
use Flarum\Sticky\DiscussionStickiedNotification;
|
||||
use Flarum\Sticky\Events\DiscussionWasStickied;
|
||||
use Flarum\Sticky\Events\DiscussionWasUnstickied;
|
||||
use Flarum\Core\Notifications\Notifier;
|
||||
use Flarum\Core\Notifications\NotificationSyncer;
|
||||
use Flarum\Core\Models\Discussion;
|
||||
use Flarum\Core\Models\User;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
class DiscussionStickiedNotifier
|
||||
{
|
||||
protected $notifier;
|
||||
protected $notifications;
|
||||
|
||||
public function __construct(Notifier $notifier)
|
||||
public function __construct(NotificationSyncer $notifications)
|
||||
{
|
||||
$this->notifier = $notifier;
|
||||
$this->notifications = $notifications;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,37 +31,28 @@ class DiscussionStickiedNotifier
|
||||
|
||||
public function whenDiscussionWasStickied(DiscussionWasStickied $event)
|
||||
{
|
||||
$post = $this->createPost($event->discussion->id, $event->user->id, true);
|
||||
|
||||
$post = $event->discussion->addPost($post);
|
||||
|
||||
if ($event->discussion->start_user_id !== $event->user->id) {
|
||||
$notification = $this->createNotification($event->discussion, $post->user, $post);
|
||||
|
||||
$this->notifier->send($notification, [$post->discussion->startUser]);
|
||||
}
|
||||
$this->stickyChanged($event->discussion, $event->user, true);
|
||||
}
|
||||
|
||||
public function whenDiscussionWasUnstickied(DiscussionWasUnstickied $event)
|
||||
{
|
||||
$post = $this->createPost($event->discussion->id, $event->user->id, false);
|
||||
|
||||
$event->discussion->addPost($post);
|
||||
|
||||
$this->notifier->retract($this->createNotification($event->discussion, $event->user));
|
||||
$this->stickyChanged($event->discussion, $event->user, false);
|
||||
}
|
||||
|
||||
protected function createPost($discussionId, $userId, $isSticky)
|
||||
protected function stickyChanged(Discussion $discussion, User $user, $isSticky)
|
||||
{
|
||||
return DiscussionStickiedPost::reply(
|
||||
$discussionId,
|
||||
$userId,
|
||||
$post = DiscussionStickiedPost::reply(
|
||||
$discussion->id,
|
||||
$user->id,
|
||||
$isSticky
|
||||
);
|
||||
}
|
||||
|
||||
protected function createNotification($discussion, $user, $post = null)
|
||||
{
|
||||
return new DiscussionStickiedNotification($discussion, $user, $post);
|
||||
$post = $discussion->addPost($post);
|
||||
|
||||
if ($discussion->start_user_id !== $user->id) {
|
||||
$notification = new DiscussionStickiedNotification($post);
|
||||
|
||||
$this->notifications->sync($notification, $post->exists ? [$discussion->startUser] : []);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ class StickyServiceProvider extends ServiceProvider
|
||||
|
||||
new DiscussionGambit('Flarum\Sticky\StickyGambit'),
|
||||
|
||||
(new NotificationType('Flarum\Sticky\DiscussionStickiedNotification'))->enableByDefault('alert'),
|
||||
(new NotificationType('Flarum\Sticky\DiscussionStickiedNotification', 'Flarum\Api\Serializers\DiscussionBasicSerializer'))->enableByDefault('alert'),
|
||||
|
||||
new Permission('discussion.sticky')
|
||||
);
|
||||
|
Reference in New Issue
Block a user