mirror of
https://github.com/flarum/framework.git
synced 2024-11-28 11:34:36 +08:00
Extract Flarum\Notification namespace
This commit is contained in:
parent
4a13cd8088
commit
b38ade986d
|
@ -13,7 +13,7 @@ namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Discussion\Discussion;
|
use Flarum\Discussion\Discussion;
|
||||||
use Flarum\User\Exception\PermissionDeniedException;
|
use Flarum\User\Exception\PermissionDeniedException;
|
||||||
use Flarum\Core\Repository\NotificationRepository;
|
use Flarum\Notification\NotificationRepository;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Tobscure\JsonApi\Document;
|
use Tobscure\JsonApi\Document;
|
||||||
|
|
||||||
|
@ -39,12 +39,12 @@ class ListNotificationsController extends AbstractListController
|
||||||
public $limit = 10;
|
public $limit = 10;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Flarum\Core\Repository\NotificationRepository
|
* @var \Flarum\Notification\NotificationRepository
|
||||||
*/
|
*/
|
||||||
protected $notifications;
|
protected $notifications;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Flarum\Core\Repository\NotificationRepository $notifications
|
* @param \Flarum\Notification\NotificationRepository $notifications
|
||||||
*/
|
*/
|
||||||
public function __construct(NotificationRepository $notifications)
|
public function __construct(NotificationRepository $notifications)
|
||||||
{
|
{
|
||||||
|
@ -80,7 +80,7 @@ class ListNotificationsController extends AbstractListController
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Flarum\Core\Notification[] $notifications
|
* @param \Flarum\Notification\Notification[] $notifications
|
||||||
*/
|
*/
|
||||||
private function loadSubjectDiscussions(array $notifications)
|
private function loadSubjectDiscussions(array $notifications)
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
namespace Flarum\Api\Serializer;
|
namespace Flarum\Api\Serializer;
|
||||||
|
|
||||||
use Flarum\Core\Notification;
|
use Flarum\Notification\Notification;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
|
||||||
class NotificationSerializer extends AbstractSerializer
|
class NotificationSerializer extends AbstractSerializer
|
||||||
|
@ -32,7 +32,7 @@ class NotificationSerializer extends AbstractSerializer
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*
|
*
|
||||||
* @param \Flarum\Core\Notification $notification
|
* @param \Flarum\Notification\Notification $notification
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
protected function getDefaultAttributes($notification)
|
protected function getDefaultAttributes($notification)
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace Flarum\Core\Command;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Flarum\User\AssertPermissionTrait;
|
use Flarum\User\AssertPermissionTrait;
|
||||||
use Flarum\Core\Notification\NotificationSyncer;
|
use Flarum\Notification\NotificationSyncer;
|
||||||
use Flarum\Post\CommentPost;
|
use Flarum\Post\CommentPost;
|
||||||
use Flarum\Discussion\DiscussionRepository;
|
use Flarum\Discussion\DiscussionRepository;
|
||||||
use Flarum\Foundation\DispatchEventsTrait;
|
use Flarum\Foundation\DispatchEventsTrait;
|
||||||
|
@ -32,7 +32,7 @@ class PostReplyHandler
|
||||||
protected $discussions;
|
protected $discussions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var NotificationSyncer
|
* @var \Flarum\Notification\NotificationSyncer
|
||||||
*/
|
*/
|
||||||
protected $notifications;
|
protected $notifications;
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ class PostReplyHandler
|
||||||
/**
|
/**
|
||||||
* @param Dispatcher $events
|
* @param Dispatcher $events
|
||||||
* @param DiscussionRepository $discussions
|
* @param DiscussionRepository $discussions
|
||||||
* @param NotificationSyncer $notifications
|
* @param \Flarum\Notification\NotificationSyncer $notifications
|
||||||
* @param PostValidator $validator
|
* @param PostValidator $validator
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
namespace Flarum\Core\Command;
|
namespace Flarum\Core\Command;
|
||||||
|
|
||||||
use Flarum\User\AssertPermissionTrait;
|
use Flarum\User\AssertPermissionTrait;
|
||||||
use Flarum\Core\Repository\NotificationRepository;
|
use Flarum\Notification\NotificationRepository;
|
||||||
|
|
||||||
class ReadAllNotificationsHandler
|
class ReadAllNotificationsHandler
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
namespace Flarum\Core\Command;
|
namespace Flarum\Core\Command;
|
||||||
|
|
||||||
use Flarum\User\AssertPermissionTrait;
|
use Flarum\User\AssertPermissionTrait;
|
||||||
use Flarum\Core\Notification;
|
use Flarum\Notification\Notification;
|
||||||
|
|
||||||
class ReadNotificationHandler
|
class ReadNotificationHandler
|
||||||
{
|
{
|
||||||
|
@ -20,7 +20,7 @@ class ReadNotificationHandler
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ReadNotification $command
|
* @param ReadNotification $command
|
||||||
* @return \Flarum\Core\Notification
|
* @return \Flarum\Notification\Notification
|
||||||
* @throws \Flarum\User\Exception\PermissionDeniedException
|
* @throws \Flarum\User\Exception\PermissionDeniedException
|
||||||
*/
|
*/
|
||||||
public function handle(ReadNotification $command)
|
public function handle(ReadNotification $command)
|
||||||
|
|
|
@ -40,7 +40,7 @@ class CoreServiceProvider extends AbstractServiceProvider
|
||||||
|
|
||||||
$this->registerAvatarsFilesystem();
|
$this->registerAvatarsFilesystem();
|
||||||
|
|
||||||
$this->app->register('Flarum\Core\Notification\NotificationServiceProvider');
|
$this->app->register('Flarum\Notification\Notification\NotificationServiceProvider');
|
||||||
$this->app->register('Flarum\Search\SearchServiceProvider');
|
$this->app->register('Flarum\Search\SearchServiceProvider');
|
||||||
$this->app->register('Flarum\Formatter\FormatterServiceProvider');
|
$this->app->register('Flarum\Formatter\FormatterServiceProvider');
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
|
|
||||||
namespace Flarum\Discussion;
|
namespace Flarum\Discussion;
|
||||||
|
|
||||||
use Flarum\Core\Notification\DiscussionRenamedBlueprint;
|
use Flarum\Notification\Blueprint\DiscussionRenamedBlueprint;
|
||||||
use Flarum\Core\Notification\NotificationSyncer;
|
use Flarum\Notification\NotificationSyncer;
|
||||||
use Flarum\Post\DiscussionRenamedPost;
|
use Flarum\Post\DiscussionRenamedPost;
|
||||||
use Flarum\Discussion\Event\Renamed;
|
use Flarum\Discussion\Event\Renamed;
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
namespace Flarum\Event;
|
namespace Flarum\Event;
|
||||||
|
|
||||||
use Flarum\Core\Notification\BlueprintInterface;
|
use Flarum\Notification\Blueprint\BlueprintInterface;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Core\Notification;
|
namespace Flarum\Notification\Blueprint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A notification BlueprintInterface, when instantiated, represents a notification about
|
* A notification BlueprintInterface, when instantiated, represents a notification about
|
|
@ -9,7 +9,7 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Core\Notification;
|
namespace Flarum\Notification\Blueprint;
|
||||||
|
|
||||||
use Flarum\Post\DiscussionRenamedPost;
|
use Flarum\Post\DiscussionRenamedPost;
|
||||||
|
|
|
@ -9,11 +9,11 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Event;
|
namespace Flarum\Notification\Event;
|
||||||
|
|
||||||
use Flarum\Core\Notification\BlueprintInterface;
|
use Flarum\Notification\Blueprint\BlueprintInterface;
|
||||||
|
|
||||||
class NotificationWillBeSent
|
class Sending
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The blueprint for the notification.
|
* The blueprint for the notification.
|
||||||
|
@ -30,7 +30,7 @@ class NotificationWillBeSent
|
||||||
public $users;
|
public $users;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param BlueprintInterface $blueprint
|
* @param \Flarum\Notification\Blueprint\BlueprintInterface $blueprint
|
||||||
* @param \Flarum\User\User[] $users
|
* @param \Flarum\User\User[] $users
|
||||||
*/
|
*/
|
||||||
public function __construct(BlueprintInterface $blueprint, array &$users)
|
public function __construct(BlueprintInterface $blueprint, array &$users)
|
|
@ -9,7 +9,7 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Core\Notification;
|
namespace Flarum\Notification;
|
||||||
|
|
||||||
interface MailableInterface
|
interface MailableInterface
|
||||||
{
|
{
|
|
@ -9,7 +9,7 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Core;
|
namespace Flarum\Notification;
|
||||||
|
|
||||||
use Flarum\Database\AbstractModel;
|
use Flarum\Database\AbstractModel;
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Core\Notification;
|
namespace Flarum\Notification;
|
||||||
|
|
||||||
use Flarum\User\User;
|
use Flarum\User\User;
|
||||||
use Illuminate\Contracts\Mail\Mailer;
|
use Illuminate\Contracts\Mail\Mailer;
|
|
@ -9,9 +9,8 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Core\Repository;
|
namespace Flarum\Notification;
|
||||||
|
|
||||||
use Flarum\Core\Notification;
|
|
||||||
use Flarum\User\User;
|
use Flarum\User\User;
|
||||||
|
|
||||||
class NotificationRepository
|
class NotificationRepository
|
|
@ -9,9 +9,8 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Core\Notification;
|
namespace Flarum\Notification;
|
||||||
|
|
||||||
use Flarum\Core\Notification;
|
|
||||||
use Flarum\Event\ConfigureNotificationTypes;
|
use Flarum\Event\ConfigureNotificationTypes;
|
||||||
use Flarum\Foundation\AbstractServiceProvider;
|
use Flarum\Foundation\AbstractServiceProvider;
|
||||||
use Flarum\User\User;
|
use Flarum\User\User;
|
||||||
|
@ -33,7 +32,7 @@ class NotificationServiceProvider extends AbstractServiceProvider
|
||||||
public function registerNotificationTypes()
|
public function registerNotificationTypes()
|
||||||
{
|
{
|
||||||
$blueprints = [
|
$blueprints = [
|
||||||
'Flarum\Core\Notification\DiscussionRenamedBlueprint' => ['alert']
|
'Flarum\Notification\Notification\DiscussionRenamedBlueprint' => ['alert']
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->app->make('events')->fire(
|
$this->app->make('events')->fire(
|
||||||
|
@ -52,7 +51,7 @@ class NotificationServiceProvider extends AbstractServiceProvider
|
||||||
in_array('alert', $enabled)
|
in_array('alert', $enabled)
|
||||||
);
|
);
|
||||||
|
|
||||||
if ((new ReflectionClass($blueprint))->implementsInterface('Flarum\Core\Notification\MailableInterface')) {
|
if ((new ReflectionClass($blueprint))->implementsInterface('Flarum\Notification\Notification\MailableInterface')) {
|
||||||
User::addPreference(
|
User::addPreference(
|
||||||
User::getNotificationPreferenceKey($type, 'email'),
|
User::getNotificationPreferenceKey($type, 'email'),
|
||||||
'boolval',
|
'boolval',
|
|
@ -9,12 +9,11 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Core\Notification;
|
namespace Flarum\Notification;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Flarum\Core\Notification;
|
use Flarum\Notification\Event\Sending;
|
||||||
use Flarum\Core\Repository\NotificationRepository;
|
use Flarum\Notification\Blueprint\BlueprintInterface;
|
||||||
use Flarum\Event\NotificationWillBeSent;
|
|
||||||
use Flarum\User\User;
|
use Flarum\User\User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -66,11 +65,11 @@ class NotificationSyncer
|
||||||
* visible to anyone else. If it is being made visible for the first time,
|
* visible to anyone else. If it is being made visible for the first time,
|
||||||
* attempt to send the user an email.
|
* attempt to send the user an email.
|
||||||
*
|
*
|
||||||
* @param BlueprintInterface $blueprint
|
* @param \Flarum\Notification\Blueprint\BlueprintInterface $blueprint
|
||||||
* @param User[] $users
|
* @param User[] $users
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function sync(BlueprintInterface $blueprint, array $users)
|
public function sync(Blueprint\BlueprintInterface $blueprint, array $users)
|
||||||
{
|
{
|
||||||
$attributes = $this->getAttributes($blueprint);
|
$attributes = $this->getAttributes($blueprint);
|
||||||
|
|
||||||
|
@ -125,7 +124,7 @@ class NotificationSyncer
|
||||||
/**
|
/**
|
||||||
* Delete a notification for all users.
|
* Delete a notification for all users.
|
||||||
*
|
*
|
||||||
* @param BlueprintInterface $blueprint
|
* @param \Flarum\Notification\Blueprint\BlueprintInterface $blueprint
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function delete(BlueprintInterface $blueprint)
|
public function delete(BlueprintInterface $blueprint)
|
||||||
|
@ -165,14 +164,14 @@ class NotificationSyncer
|
||||||
* Create a notification record and send an email (depending on user
|
* Create a notification record and send an email (depending on user
|
||||||
* preference) from a blueprint to a list of recipients.
|
* preference) from a blueprint to a list of recipients.
|
||||||
*
|
*
|
||||||
* @param BlueprintInterface $blueprint
|
* @param \Flarum\Notification\Blueprint\BlueprintInterface $blueprint
|
||||||
* @param User[] $recipients
|
* @param User[] $recipients
|
||||||
*/
|
*/
|
||||||
protected function sendNotifications(BlueprintInterface $blueprint, array $recipients)
|
protected function sendNotifications(Blueprint\BlueprintInterface $blueprint, array $recipients)
|
||||||
{
|
{
|
||||||
$now = Carbon::now('utc')->toDateTimeString();
|
$now = Carbon::now('utc')->toDateTimeString();
|
||||||
|
|
||||||
event(new NotificationWillBeSent($blueprint, $recipients));
|
event(new Sending($blueprint, $recipients));
|
||||||
|
|
||||||
$attributes = $this->getAttributes($blueprint);
|
$attributes = $this->getAttributes($blueprint);
|
||||||
|
|
||||||
|
@ -220,10 +219,10 @@ class NotificationSyncer
|
||||||
* Construct an array of attributes to be stored in a notification record in
|
* Construct an array of attributes to be stored in a notification record in
|
||||||
* the database, given a notification blueprint.
|
* the database, given a notification blueprint.
|
||||||
*
|
*
|
||||||
* @param BlueprintInterface $blueprint
|
* @param \Flarum\Notification\Blueprint\BlueprintInterface $blueprint
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getAttributes(BlueprintInterface $blueprint)
|
protected function getAttributes(Blueprint\BlueprintInterface $blueprint)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'type' => $blueprint::getType(),
|
'type' => $blueprint::getType(),
|
|
@ -13,7 +13,7 @@ namespace Flarum\User;
|
||||||
|
|
||||||
use DomainException;
|
use DomainException;
|
||||||
use Flarum\Group\Group;
|
use Flarum\Group\Group;
|
||||||
use Flarum\Core\Notification;
|
use Flarum\Notification\Notification;
|
||||||
use Flarum\Group\Permission;
|
use Flarum\Group\Permission;
|
||||||
use Flarum\Foundation\EventGeneratorTrait;
|
use Flarum\Foundation\EventGeneratorTrait;
|
||||||
use Flarum\Database\ScopeVisibilityTrait;
|
use Flarum\Database\ScopeVisibilityTrait;
|
||||||
|
@ -632,7 +632,7 @@ class User extends AbstractModel
|
||||||
*/
|
*/
|
||||||
public function notifications()
|
public function notifications()
|
||||||
{
|
{
|
||||||
return $this->hasMany('Flarum\Core\Notification');
|
return $this->hasMany('Flarum\Notification\Notification');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user