1
0
mirror of https://github.com/flarum/core.git synced 2025-08-03 23:17:43 +02:00

Update notification architecture

This commit is contained in:
Toby Zerner
2015-05-14 22:42:52 +09:30
parent 55a4d4663a
commit 798bdd3e68
3 changed files with 25 additions and 26 deletions

View File

@@ -4,18 +4,11 @@ import username from 'flarum/helpers/username';
export default class NotificationDiscussionStickied extends Notification { export default class NotificationDiscussionStickied extends Notification {
view() { view() {
var notification = this.props.notification; var notification = this.props.notification;
var discussion = notification.subject();
return super.view({ return super.view({
href: app.route('discussion.near', { href: app.route.discussion(notification.subject(), notification.content().postNumber),
id: discussion.id(),
slug: discussion.slug(),
near: notification.content().postNumber
}),
config: m.route,
title: discussion.title(),
icon: 'thumb-tack', icon: 'thumb-tack',
content: ['Stickied by ', username(notification.sender())] content: [username(notification.sender()), ' stickied']
}); });
} }
} }

View File

@@ -1,30 +1,38 @@
<?php namespace Flarum\Sticky; <?php namespace Flarum\Sticky;
use Flarum\Core\Models\User; use Flarum\Core\Models\User;
use Flarum\Core\Models\Discussion;
use Flarum\Core\Notifications\Types\Notification; use Flarum\Core\Notifications\Types\Notification;
use Flarum\Core\Notifications\Types\AlertableNotification; use Flarum\Core\Notifications\Types\AlertableNotification;
class DiscussionStickiedNotification extends Notification implements AlertableNotification class DiscussionStickiedNotification extends Notification implements AlertableNotification
{ {
public $post; protected $discussion;
public function __construct(User $recipient, User $sender, DiscussionStickiedPost $post) protected $sender;
protected $post;
public function __construct(Discussion $discussion, User $sender, DiscussionStickiedPost $post = null)
{ {
$this->discussion = $discussion;
$this->sender = $sender;
$this->post = $post; $this->post = $post;
parent::__construct($recipient, $sender);
} }
public function getSubject() public function getSubject()
{ {
return $this->post->discussion; return $this->discussion;
}
public function getSender()
{
return $this->sender;
} }
public function getAlertData() public function getAlertData()
{ {
return [ return ['postNumber' => $this->post->number];
'postNumber' => $this->post->number
];
} }
public static function getType() public static function getType()

View File

@@ -34,7 +34,9 @@ class DiscussionStickiedNotifier
$post = $event->discussion->addPost($post); $post = $event->discussion->addPost($post);
if ($event->discussion->start_user_id !== $event->user->id) { 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); $post = $this->createPost($event->discussion->id, $event->user->id, false);
$event->discussion->addPost($post); $event->discussion->addPost($post);
$this->notifier->retract($this->createNotification($event->discussion, $event->user));
} }
protected function createPost($discussionId, $userId, $isSticky) 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( return new DiscussionStickiedNotification($discussion, $user, $post);
$post->discussion->startUser,
$post->user,
$post
);
$this->notifier->send($notification);
} }
} }