2015-05-14 20:31:03 +08:00
|
|
|
<?php
|
|
|
|
|
2015-09-04 11:01:19 +08:00
|
|
|
/*
|
|
|
|
* This file is part of Flarum.
|
|
|
|
*
|
2019-11-30 07:02:17 +08:00
|
|
|
* For detailed copyright and license information, please view the
|
|
|
|
* LICENSE file that was distributed with this source code.
|
2015-09-04 11:01:19 +08:00
|
|
|
*/
|
|
|
|
|
2021-05-05 02:57:29 +08:00
|
|
|
namespace Flarum\Mentions;
|
|
|
|
|
2020-12-09 00:15:52 +08:00
|
|
|
use Flarum\Api\Controller;
|
|
|
|
use Flarum\Api\Serializer\BasicPostSerializer;
|
2018-12-16 00:23:48 +08:00
|
|
|
use Flarum\Api\Serializer\PostSerializer;
|
2018-01-17 06:26:21 +08:00
|
|
|
use Flarum\Extend;
|
2018-12-16 00:23:48 +08:00
|
|
|
use Flarum\Mentions\Notification\PostMentionedBlueprint;
|
|
|
|
use Flarum\Mentions\Notification\UserMentionedBlueprint;
|
|
|
|
use Flarum\Post\Event\Deleted;
|
|
|
|
use Flarum\Post\Event\Hidden;
|
|
|
|
use Flarum\Post\Event\Posted;
|
|
|
|
use Flarum\Post\Event\Restored;
|
|
|
|
use Flarum\Post\Event\Revised;
|
2021-05-05 02:57:29 +08:00
|
|
|
use Flarum\Post\Filter\PostFilterer;
|
2020-04-24 21:55:50 +08:00
|
|
|
use Flarum\Post\Post;
|
|
|
|
use Flarum\User\User;
|
2015-05-14 20:31:03 +08:00
|
|
|
|
2018-01-17 06:26:21 +08:00
|
|
|
return [
|
2018-07-23 22:29:38 +08:00
|
|
|
(new Extend\Frontend('forum'))
|
2018-06-20 12:05:33 +08:00
|
|
|
->js(__DIR__.'/js/dist/forum.js')
|
2018-07-23 22:29:38 +08:00
|
|
|
->css(__DIR__.'/less/forum.less'),
|
2018-06-20 12:05:33 +08:00
|
|
|
|
2021-04-21 17:58:54 +08:00
|
|
|
(new Extend\Frontend('admin'))
|
|
|
|
->js(__DIR__.'/js/dist/admin.js'),
|
|
|
|
|
2018-12-15 19:06:08 +08:00
|
|
|
(new Extend\Formatter)
|
2021-03-02 12:26:35 +08:00
|
|
|
->configure(ConfigureMentions::class)
|
|
|
|
->render(Formatter\FormatPostMentions::class)
|
2021-04-21 17:58:54 +08:00
|
|
|
->render(Formatter\FormatUserMentions::class)
|
|
|
|
->unparse(Formatter\UnparsePostMentions::class)
|
|
|
|
->unparse(Formatter\UnparseUserMentions::class),
|
2018-12-15 19:06:08 +08:00
|
|
|
|
2020-04-24 21:55:50 +08:00
|
|
|
(new Extend\Model(Post::class))
|
|
|
|
->belongsToMany('mentionedBy', Post::class, 'post_mentions_post', 'mentions_post_id', 'post_id')
|
|
|
|
->belongsToMany('mentionsPosts', Post::class, 'post_mentions_post', 'post_id', 'mentions_post_id')
|
|
|
|
->belongsToMany('mentionsUsers', User::class, 'post_mentions_user', 'post_id', 'mentions_user_id'),
|
|
|
|
|
2020-06-20 10:27:37 +08:00
|
|
|
new Extend\Locales(__DIR__.'/locale'),
|
|
|
|
|
2020-07-17 18:10:47 +08:00
|
|
|
(new Extend\View)
|
|
|
|
->namespace('flarum-mentions', __DIR__.'/views'),
|
|
|
|
|
2020-11-01 06:43:02 +08:00
|
|
|
(new Extend\Notification())
|
|
|
|
->type(PostMentionedBlueprint::class, PostSerializer::class, ['alert'])
|
|
|
|
->type(UserMentionedBlueprint::class, PostSerializer::class, ['alert']),
|
|
|
|
|
2020-12-09 00:15:52 +08:00
|
|
|
(new Extend\ApiSerializer(BasicPostSerializer::class))
|
|
|
|
->hasMany('mentionedBy', BasicPostSerializer::class)
|
|
|
|
->hasMany('mentionsPosts', BasicPostSerializer::class)
|
|
|
|
->hasMany('mentionsUsers', BasicPostSerializer::class),
|
|
|
|
|
|
|
|
(new Extend\ApiController(Controller\ShowDiscussionController::class))
|
|
|
|
->addInclude(['posts.mentionedBy', 'posts.mentionedBy.user', 'posts.mentionedBy.discussion']),
|
|
|
|
|
|
|
|
(new Extend\ApiController(Controller\ShowPostController::class))
|
|
|
|
->addInclude(['mentionedBy', 'mentionedBy.user', 'mentionedBy.discussion']),
|
2018-12-16 00:23:48 +08:00
|
|
|
|
2020-12-09 00:15:52 +08:00
|
|
|
(new Extend\ApiController(Controller\ListPostsController::class))
|
|
|
|
->addInclude(['mentionedBy', 'mentionedBy.user', 'mentionedBy.discussion']),
|
2018-12-16 00:23:48 +08:00
|
|
|
|
2020-12-09 00:15:52 +08:00
|
|
|
(new Extend\ApiController(Controller\CreatePostController::class))
|
|
|
|
->addInclude(['mentionsPosts', 'mentionsPosts.mentionedBy']),
|
2015-10-11 10:32:57 +08:00
|
|
|
|
2020-12-09 00:15:52 +08:00
|
|
|
(new Extend\ApiController(Controller\AbstractSerializeController::class))
|
|
|
|
->prepareDataForSerialization(FilterVisiblePosts::class),
|
|
|
|
|
2021-04-21 17:58:54 +08:00
|
|
|
(new Extend\Settings)
|
|
|
|
->serializeToForum('allowUsernameMentionFormat', 'flarum-mentions.allow_username_format', 'boolval'),
|
|
|
|
|
2020-12-09 00:15:52 +08:00
|
|
|
(new Extend\Event())
|
|
|
|
->listen(Posted::class, Listener\UpdateMentionsMetadataWhenVisible::class)
|
|
|
|
->listen(Restored::class, Listener\UpdateMentionsMetadataWhenVisible::class)
|
|
|
|
->listen(Revised::class, Listener\UpdateMentionsMetadataWhenVisible::class)
|
|
|
|
->listen(Hidden::class, Listener\UpdateMentionsMetadataWhenInvisible::class)
|
2021-05-05 02:57:29 +08:00
|
|
|
->listen(Deleted::class, Listener\UpdateMentionsMetadataWhenInvisible::class),
|
|
|
|
|
|
|
|
(new Extend\Filter(PostFilterer::class))
|
|
|
|
->addFilter(Filter\MentionedFilter::class),
|
2018-01-17 06:26:21 +08:00
|
|
|
];
|