From 798bdd3e68998bb5f32d5ffe92ee7e56f4106a7b Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Thu, 14 May 2015 22:42:52 +0930 Subject: [PATCH] Update notification architecture --- .../notification-discussion-stickied.js | 11 ++------- .../src/DiscussionStickiedNotification.php | 24 ++++++++++++------- .../Handlers/DiscussionStickiedNotifier.php | 16 ++++++------- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/extensions/sticky/js/src/components/notification-discussion-stickied.js b/extensions/sticky/js/src/components/notification-discussion-stickied.js index 89bc169b8..08e04fc89 100644 --- a/extensions/sticky/js/src/components/notification-discussion-stickied.js +++ b/extensions/sticky/js/src/components/notification-discussion-stickied.js @@ -4,18 +4,11 @@ import username from 'flarum/helpers/username'; export default class NotificationDiscussionStickied extends Notification { view() { var notification = this.props.notification; - var discussion = notification.subject(); return super.view({ - href: app.route('discussion.near', { - id: discussion.id(), - slug: discussion.slug(), - near: notification.content().postNumber - }), - config: m.route, - title: discussion.title(), + href: app.route.discussion(notification.subject(), notification.content().postNumber), icon: 'thumb-tack', - content: ['Stickied by ', username(notification.sender())] + content: [username(notification.sender()), ' stickied'] }); } } diff --git a/extensions/sticky/src/DiscussionStickiedNotification.php b/extensions/sticky/src/DiscussionStickiedNotification.php index 40e407a50..97047f426 100644 --- a/extensions/sticky/src/DiscussionStickiedNotification.php +++ b/extensions/sticky/src/DiscussionStickiedNotification.php @@ -1,30 +1,38 @@ discussion = $discussion; + $this->sender = $sender; $this->post = $post; - - parent::__construct($recipient, $sender); } public function getSubject() { - return $this->post->discussion; + return $this->discussion; + } + + public function getSender() + { + return $this->sender; } public function getAlertData() { - return [ - 'postNumber' => $this->post->number - ]; + return ['postNumber' => $this->post->number]; } public static function getType() diff --git a/extensions/sticky/src/Handlers/DiscussionStickiedNotifier.php b/extensions/sticky/src/Handlers/DiscussionStickiedNotifier.php index fdfa28aa1..39ccb29e7 100755 --- a/extensions/sticky/src/Handlers/DiscussionStickiedNotifier.php +++ b/extensions/sticky/src/Handlers/DiscussionStickiedNotifier.php @@ -34,7 +34,9 @@ class DiscussionStickiedNotifier $post = $event->discussion->addPost($post); if ($event->discussion->start_user_id !== $event->user->id) { - $this->sendNotification($post); + $notification = $this->createNotification($event->discussion, $post->user, $post); + + $this->notifier->send($notification, [$post->discussion->startUser]); } } @@ -43,6 +45,8 @@ class DiscussionStickiedNotifier $post = $this->createPost($event->discussion->id, $event->user->id, false); $event->discussion->addPost($post); + + $this->notifier->retract($this->createNotification($event->discussion, $event->user)); } protected function createPost($discussionId, $userId, $isSticky) @@ -54,14 +58,8 @@ class DiscussionStickiedNotifier ); } - protected function sendNotification(DiscussionStickiedPost $post) + protected function createNotification($discussion, $user, $post = null) { - $notification = new DiscussionStickiedNotification( - $post->discussion->startUser, - $post->user, - $post - ); - - $this->notifier->send($notification); + return new DiscussionStickiedNotification($discussion, $user, $post); } }