2015-08-27 07:40:18 +08:00
|
|
|
<?php
|
2015-08-26 14:48:58 +08:00
|
|
|
/*
|
|
|
|
* This file is part of Flarum.
|
|
|
|
*
|
|
|
|
* (c) Toby Zerner <toby.zerner@gmail.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Flarum\Core\Notifications;
|
2015-07-01 21:04:11 +08:00
|
|
|
|
2015-07-18 21:29:47 +08:00
|
|
|
use Flarum\Core\Users\User;
|
|
|
|
use Flarum\Events\RegisterNotificationTypes;
|
2015-07-01 21:04:11 +08:00
|
|
|
use Flarum\Support\ServiceProvider;
|
|
|
|
use Flarum\Extend;
|
2015-07-18 21:29:47 +08:00
|
|
|
use ReflectionClass;
|
2015-07-01 21:04:11 +08:00
|
|
|
|
|
|
|
class NotificationsServiceProvider extends ServiceProvider
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Bootstrap the application events.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function boot()
|
|
|
|
{
|
2015-07-18 21:29:47 +08:00
|
|
|
$events = $this->app->make('events');
|
2015-07-01 21:04:11 +08:00
|
|
|
|
2015-07-18 21:29:47 +08:00
|
|
|
$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)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2015-07-01 21:04:11 +08:00
|
|
|
}
|
|
|
|
|
2015-07-04 10:54:48 +08:00
|
|
|
/**
|
|
|
|
* Register the service provider.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2015-07-01 21:04:11 +08:00
|
|
|
public function register()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|