mirror of
https://github.com/flarum/framework.git
synced 2025-02-20 23:24:55 +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() {
|
view() {
|
||||||
var notification = this.props.notification;
|
var notification = this.props.notification;
|
||||||
var discussion = notification.subject();
|
var discussion = notification.subject();
|
||||||
var category = discussion.category();
|
|
||||||
|
|
||||||
return super.view({
|
return super.view({
|
||||||
href: app.route('discussion.near', {
|
href: app.route.discussion(discussion, notification.content().postNumber),
|
||||||
id: discussion.id(),
|
|
||||||
slug: discussion.slug(),
|
|
||||||
near: notification.content().postNumber
|
|
||||||
}),
|
|
||||||
config: m.route,
|
|
||||||
title: discussion.title(),
|
|
||||||
icon: 'arrow-right',
|
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;
|
<?php namespace Flarum\Categories;
|
||||||
|
|
||||||
use Flarum\Core\Models\User;
|
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\Notification;
|
||||||
use Flarum\Core\Notifications\Types\AlertableNotification;
|
use Flarum\Core\Notifications\Types\AlertableNotification;
|
||||||
|
|
||||||
class DiscussionMovedNotification extends Notification implements 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;
|
$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()
|
||||||
|
@ -32,7 +32,13 @@ class DiscussionMovedNotifier
|
|||||||
$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($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
|
$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…
x
Reference in New Issue
Block a user