1
0
mirror of https://github.com/flarum/core.git synced 2025-07-31 13:40:20 +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 {
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']
});
}
}

View File

@@ -1,30 +1,38 @@
<?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;
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;
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()

View File

@@ -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);
}
}