framework/extensions/subscriptions/extend.php

73 lines
2.7 KiB
PHP
Raw Normal View History

2015-06-26 10:54:07 +08:00
<?php
2015-09-04 11:00:01 +08:00
/*
* This file is part of Flarum.
*
2019-11-30 07:02:31 +08:00
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
2015-09-04 11:00:01 +08:00
*/
2024-02-26 22:27:04 +08:00
use Flarum\Api\Resource;
use Flarum\Approval\Event\PostWasApproved;
use Flarum\Discussion\Event\Saving;
2021-03-14 05:32:48 +08:00
use Flarum\Discussion\Search\DiscussionSearcher;
use Flarum\Discussion\UserState;
use Flarum\Extend;
use Flarum\Post\Event\Deleted;
use Flarum\Post\Event\Hidden;
use Flarum\Post\Event\Posted;
use Flarum\Post\Event\Restored;
use Flarum\Search\Database\DatabaseSearchDriver;
2024-02-26 22:27:04 +08:00
use Flarum\Subscriptions\Api\UserResourceFields;
use Flarum\Subscriptions\Filter\SubscriptionFilter;
2021-03-14 05:32:48 +08:00
use Flarum\Subscriptions\HideIgnoredFromAllDiscussionsPage;
2015-10-11 15:00:11 +08:00
use Flarum\Subscriptions\Listener;
use Flarum\Subscriptions\Notification\FilterVisiblePostsBeforeSending;
use Flarum\Subscriptions\Notification\NewPostBlueprint;
use Flarum\User\User;
2015-06-26 10:54:07 +08:00
return [
(new Extend\Frontend('admin'))
->js(__DIR__.'/js/dist/admin.js'),
(new Extend\Frontend('forum'))
->js(__DIR__.'/js/dist/forum.js')
->css(__DIR__.'/less/forum.less')
2018-07-23 22:33:49 +08:00
->route('/following', 'following'),
new Extend\Locales(__DIR__.'/locale'),
(new Extend\Model(User::class))
->cast('last_read_post_number', 'integer'),
(new Extend\Model(UserState::class))
->cast('subscription', 'string'),
(new Extend\View)
->namespace('flarum-subscriptions', __DIR__.'/views'),
(new Extend\Notification())
2024-02-26 22:27:04 +08:00
->type(NewPostBlueprint::class, ['alert', 'email'])
->beforeSending(FilterVisiblePostsBeforeSending::class),
2024-02-26 22:27:04 +08:00
(new Extend\ApiResource(Resource\DiscussionResource::class))
->fields(UserResourceFields::class),
2020-12-09 01:37:40 +08:00
(new Extend\Event())
->listen(Saving::class, Listener\SaveSubscriptionToDatabase::class)
->listen(Posted::class, Listener\SendNotificationWhenReplyIsPosted::class)
->listen(PostWasApproved::class, Listener\SendNotificationWhenReplyIsPosted::class)
2020-12-09 01:37:40 +08:00
->listen(Hidden::class, Listener\DeleteNotificationWhenPostIsHiddenOrDeleted::class)
->listen(Restored::class, Listener\RestoreNotificationWhenPostIsRestored::class)
->listen(Deleted::class, Listener\DeleteNotificationWhenPostIsHiddenOrDeleted::class)
->listen(Posted::class, Listener\FollowAfterReply::class),
(new Extend\SearchDriver(DatabaseSearchDriver::class))
->addFilter(DiscussionSearcher::class, SubscriptionFilter::class)
->addMutator(DiscussionSearcher::class, HideIgnoredFromAllDiscussionsPage::class),
(new Extend\User())
2024-02-26 22:27:04 +08:00
->registerPreference('followAfterReply', 'boolval', false)
->registerPreference('flarum-subscriptions.notify_for_all_posts', 'boolval', false),
];