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
|
|
|
*/
|
|
|
|
|
2018-12-16 22:00:02 +08:00
|
|
|
use Flarum\Api\Serializer\BasicDiscussionSerializer;
|
2020-12-09 01:37:40 +08:00
|
|
|
use Flarum\Api\Serializer\DiscussionSerializer;
|
2022-11-07 19:52:28 +08:00
|
|
|
use Flarum\Approval\Event\PostWasApproved;
|
2020-12-09 01:37:40 +08:00
|
|
|
use Flarum\Discussion\Discussion;
|
2018-12-16 22:00:02 +08:00
|
|
|
use Flarum\Discussion\Event\Saving;
|
2021-03-14 05:32:48 +08:00
|
|
|
use Flarum\Discussion\Filter\DiscussionFilterer;
|
|
|
|
use Flarum\Discussion\Search\DiscussionSearcher;
|
2018-01-17 06:21:48 +08:00
|
|
|
use Flarum\Extend;
|
2018-12-16 22:00:02 +08:00
|
|
|
use Flarum\Post\Event\Deleted;
|
|
|
|
use Flarum\Post\Event\Hidden;
|
|
|
|
use Flarum\Post\Event\Posted;
|
|
|
|
use Flarum\Post\Event\Restored;
|
2021-03-14 05:32:48 +08:00
|
|
|
use Flarum\Subscriptions\HideIgnoredFromAllDiscussionsPage;
|
2015-10-11 15:00:11 +08:00
|
|
|
use Flarum\Subscriptions\Listener;
|
2018-12-16 22:00:02 +08:00
|
|
|
use Flarum\Subscriptions\Notification\NewPostBlueprint;
|
2021-03-14 05:33:02 +08:00
|
|
|
use Flarum\Subscriptions\Query\SubscriptionFilterGambit;
|
2015-06-26 10:54:07 +08:00
|
|
|
|
2018-01-17 06:21:48 +08:00
|
|
|
return [
|
2018-07-23 22:31:08 +08:00
|
|
|
(new Extend\Frontend('forum'))
|
2018-06-20 12:06:12 +08:00
|
|
|
->js(__DIR__.'/js/dist/forum.js')
|
2018-07-23 22:31:08 +08:00
|
|
|
->css(__DIR__.'/less/forum.less')
|
2018-07-23 22:33:49 +08:00
|
|
|
->route('/following', 'following'),
|
2018-06-20 12:06:12 +08:00
|
|
|
|
2020-06-20 10:22:54 +08:00
|
|
|
new Extend\Locales(__DIR__.'/locale'),
|
|
|
|
|
2020-07-17 18:11:25 +08:00
|
|
|
(new Extend\View)
|
|
|
|
->namespace('flarum-subscriptions', __DIR__.'/views'),
|
|
|
|
|
2020-11-01 06:42:30 +08:00
|
|
|
(new Extend\Notification())
|
|
|
|
->type(NewPostBlueprint::class, BasicDiscussionSerializer::class, ['alert', 'email']),
|
|
|
|
|
2020-12-09 01:37:40 +08:00
|
|
|
(new Extend\ApiSerializer(DiscussionSerializer::class))
|
|
|
|
->attribute('subscription', function (DiscussionSerializer $serializer, Discussion $discussion) {
|
|
|
|
if ($state = $discussion->state) {
|
2021-03-19 00:38:21 +08:00
|
|
|
return $state->subscription;
|
2020-12-09 01:37:40 +08:00
|
|
|
}
|
|
|
|
}),
|
2018-12-16 22:00:02 +08:00
|
|
|
|
2020-12-09 01:43:59 +08:00
|
|
|
(new Extend\User())
|
|
|
|
->registerPreference('followAfterReply', 'boolval', false),
|
|
|
|
|
2020-12-09 01:37:40 +08:00
|
|
|
(new Extend\Event())
|
|
|
|
->listen(Saving::class, Listener\SaveSubscriptionToDatabase::class)
|
|
|
|
->listen(Posted::class, Listener\SendNotificationWhenReplyIsPosted::class)
|
2022-11-07 19:52:28 +08:00
|
|
|
->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),
|
2020-12-09 01:43:59 +08:00
|
|
|
|
2021-03-14 05:32:48 +08:00
|
|
|
(new Extend\Filter(DiscussionFilterer::class))
|
|
|
|
->addFilter(SubscriptionFilterGambit::class)
|
|
|
|
->addFilterMutator(HideIgnoredFromAllDiscussionsPage::class),
|
|
|
|
|
|
|
|
(new Extend\SimpleFlarumSearch(DiscussionSearcher::class))
|
|
|
|
->addGambit(SubscriptionFilterGambit::class),
|
2022-08-31 17:13:51 +08:00
|
|
|
|
|
|
|
(new Extend\User())
|
|
|
|
->registerPreference('flarum-subscriptions.notify_for_all_posts', 'boolval', false),
|
2018-01-17 06:21:48 +08:00
|
|
|
];
|