mirror of
https://github.com/flarum/core.git
synced 2025-08-01 22:20:21 +02:00
Update for new notifications API
This commit is contained in:
@@ -1,38 +1,29 @@
|
|||||||
<?php namespace Flarum\Sticky;
|
<?php namespace Flarum\Sticky;
|
||||||
|
|
||||||
use Flarum\Core\Models\User;
|
use Flarum\Core\Notifications\NotificationAbstract;
|
||||||
use Flarum\Core\Models\Discussion;
|
|
||||||
use Flarum\Core\Notifications\Types\Notification;
|
|
||||||
use Flarum\Core\Notifications\Types\AlertableNotification;
|
|
||||||
|
|
||||||
class DiscussionStickiedNotification extends Notification implements AlertableNotification
|
class DiscussionStickiedNotification extends NotificationAbstract
|
||||||
{
|
{
|
||||||
protected $discussion;
|
|
||||||
|
|
||||||
protected $sender;
|
|
||||||
|
|
||||||
protected $post;
|
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;
|
$this->post = $post;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSubject()
|
public function getSubject()
|
||||||
{
|
{
|
||||||
return $this->discussion;
|
return $this->post->discussion;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSender()
|
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()
|
public static function getType()
|
||||||
|
@@ -4,16 +4,18 @@ use Flarum\Sticky\DiscussionStickiedPost;
|
|||||||
use Flarum\Sticky\DiscussionStickiedNotification;
|
use Flarum\Sticky\DiscussionStickiedNotification;
|
||||||
use Flarum\Sticky\Events\DiscussionWasStickied;
|
use Flarum\Sticky\Events\DiscussionWasStickied;
|
||||||
use Flarum\Sticky\Events\DiscussionWasUnstickied;
|
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;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
|
|
||||||
class DiscussionStickiedNotifier
|
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)
|
public function whenDiscussionWasStickied(DiscussionWasStickied $event)
|
||||||
{
|
{
|
||||||
$post = $this->createPost($event->discussion->id, $event->user->id, true);
|
$this->stickyChanged($event->discussion, $event->user, 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]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function whenDiscussionWasUnstickied(DiscussionWasUnstickied $event)
|
public function whenDiscussionWasUnstickied(DiscussionWasUnstickied $event)
|
||||||
{
|
{
|
||||||
$post = $this->createPost($event->discussion->id, $event->user->id, false);
|
$this->stickyChanged($event->discussion, $event->user, false);
|
||||||
|
|
||||||
$event->discussion->addPost($post);
|
|
||||||
|
|
||||||
$this->notifier->retract($this->createNotification($event->discussion, $event->user));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createPost($discussionId, $userId, $isSticky)
|
protected function stickyChanged(Discussion $discussion, User $user, $isSticky)
|
||||||
{
|
{
|
||||||
return DiscussionStickiedPost::reply(
|
$post = DiscussionStickiedPost::reply(
|
||||||
$discussionId,
|
$discussion->id,
|
||||||
$userId,
|
$user->id,
|
||||||
$isSticky
|
$isSticky
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
protected function createNotification($discussion, $user, $post = null)
|
$post = $discussion->addPost($post);
|
||||||
{
|
|
||||||
return new DiscussionStickiedNotification($discussion, $user, $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 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')
|
new Permission('discussion.sticky')
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user