mirror of
https://github.com/flarum/framework.git
synced 2025-02-18 12:33:22 +08:00
Update notification architecture
This commit is contained in:
parent
32efe11986
commit
11fcfbba58
|
@ -6,18 +6,11 @@ export default class NotificationDiscussionMoved extends Notification {
|
|||
view() {
|
||||
var notification = this.props.notification;
|
||||
var discussion = notification.subject();
|
||||
var category = discussion.category();
|
||||
|
||||
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(discussion, notification.content().postNumber),
|
||||
icon: 'arrow-right',
|
||||
content: ['Moved to ', categoryLabel(category), ' by ', username(notification.sender())]
|
||||
content: [username(notification.sender()), ' moved to ', categoryLabel(discussion.category())]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,30 +1,39 @@
|
|||
<?php namespace Flarum\Categories;
|
||||
|
||||
use Flarum\Core\Models\User;
|
||||
use Flarum\Core\Models\Discussion;
|
||||
use Flarum\Core\Models\Notification as NotificationModel;
|
||||
use Flarum\Core\Notifications\Types\Notification;
|
||||
use Flarum\Core\Notifications\Types\AlertableNotification;
|
||||
|
||||
class DiscussionMovedNotification extends Notification implements AlertableNotification
|
||||
{
|
||||
public $post;
|
||||
protected $discussion;
|
||||
|
||||
public function __construct(User $recipient, User $sender, DiscussionMovedPost $post)
|
||||
protected $sender;
|
||||
|
||||
protected $post;
|
||||
|
||||
public function __construct(Discussion $discussion, User $sender, DiscussionMovedPost $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()
|
||||
|
|
|
@ -32,7 +32,13 @@ class DiscussionMovedNotifier
|
|||
$post = $event->discussion->addPost($post);
|
||||
|
||||
if ($event->discussion->start_user_id !== $event->user->id) {
|
||||
$this->sendNotification($event, $post);
|
||||
$notification = new DiscussionMovedNotification($event->discussion, $post->user, $post);
|
||||
|
||||
if ($post->exists) {
|
||||
$this->notifier->send($notification, [$post->discussion->startUser]);
|
||||
} else {
|
||||
$this->notifier->retract($notification);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,16 +51,4 @@ class DiscussionMovedNotifier
|
|||
$event->discussion->category_id
|
||||
);
|
||||
}
|
||||
|
||||
protected function sendNotification(DiscussionWasMoved $event, DiscussionMovedPost $post)
|
||||
{
|
||||
$notification = new DiscussionMovedNotification(
|
||||
$event->discussion->startUser,
|
||||
$event->user,
|
||||
$post,
|
||||
$event->discussion->category_id
|
||||
);
|
||||
|
||||
$this->notifier->send($notification);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user