1
0
mirror of https://github.com/flarum/core.git synced 2025-10-18 10:16:09 +02:00

Rework public API based on events

This commit is contained in:
Toby Zerner
2015-07-18 22:59:47 +09:30
parent 5085c09c30
commit 57650fa648
136 changed files with 1157 additions and 1245 deletions

View File

@@ -1,30 +0,0 @@
<?php namespace Flarum\Core\Notifications\Events;
use Flarum\Core\Notifications\Blueprint;
class NotificationWillBeSent
{
/**
* The blueprint for the notification.
*
* @var Blueprint
*/
public $blueprint;
/**
* The users that the notification will be sent to.
*
* @var array
*/
public $users;
/**
* @param Blueprint $blueprint
* @param \Flarum\Core\Users\User[] $users
*/
public function __construct(Blueprint $blueprint, array &$users)
{
$this->blueprint = $blueprint;
$this->users = $users;
}
}

View File

@@ -1,6 +1,6 @@
<?php namespace Flarum\Core\Notifications\Listeners;
use Flarum\Core\Discussions\Events\DiscussionWasRenamed;
use Flarum\Events\DiscussionWasRenamed;
use Flarum\Core\Posts\DiscussionRenamedPost;
use Flarum\Core\Notifications\DiscussionRenamedBlueprint;
use Flarum\Core\Notifications\NotificationSyncer;
@@ -30,7 +30,7 @@ class DiscussionRenamedNotifier
}
/**
* @param DiscussionWasRenamed $event
* @param \Flarum\Events\DiscussionWasRenamed $event
*/
public function whenDiscussionWasRenamed(DiscussionWasRenamed $event)
{

View File

@@ -31,7 +31,7 @@ class Notification extends Model
/**
* {@inheritdoc}
*/
protected static $dateAttributes = ['time'];
protected $dates = ['time'];
/**
* A map of notification types and the model classes to use for their

View File

@@ -1,6 +1,6 @@
<?php namespace Flarum\Core\Notifications;
use Flarum\Core\Notifications\Events\NotificationWillBeSent;
use Flarum\Events\NotificationWillBeSent;
use Flarum\Core\Users\User;
use Carbon\Carbon;

View File

@@ -1,7 +1,10 @@
<?php namespace Flarum\Core\Notifications;
use Flarum\Core\Users\User;
use Flarum\Events\RegisterNotificationTypes;
use Flarum\Support\ServiceProvider;
use Flarum\Extend;
use ReflectionClass;
class NotificationsServiceProvider extends ServiceProvider
{
@@ -12,13 +15,46 @@ class NotificationsServiceProvider extends ServiceProvider
*/
public function boot()
{
$this->extend([
(new Extend\EventSubscriber('Flarum\Core\Notifications\Listeners\DiscussionRenamedNotifier')),
$events = $this->app->make('events');
(new Extend\NotificationType('Flarum\Core\Notifications\DiscussionRenamedBlueprint'))
->subjectSerializer('Flarum\Api\Serializers\DiscussionBasicSerializer')
->enableByDefault('alert')
]);
$events->subscribe('Flarum\Core\Notifications\Listeners\DiscussionRenamedNotifier');
$this->registerNotificationTypes();
}
/**
* Register notification types.
*
* @return void
*/
public function registerNotificationTypes()
{
$blueprints = [
'Flarum\Core\Notifications\DiscussionRenamedBlueprint' => ['alert']
];
event(new RegisterNotificationTypes($blueprints));
foreach ($blueprints as $blueprint => $enabled) {
Notification::setSubjectModel(
$type = $blueprint::getType(),
$blueprint::getSubjectModel()
);
User::addPreference(
User::getNotificationPreferenceKey($type, 'alert'),
'boolval',
in_array('alert', $enabled)
);
if ((new ReflectionClass($blueprint))->implementsInterface('Flarum\Core\Notifications\MailableBlueprint')) {
User::addPreference(
User::getNotificationPreferenceKey($type, 'email'),
'boolval',
in_array('email', $enabled)
);
}
}
}
/**