2015-05-14 22:01:03 +09:30
|
|
|
<?php
|
|
|
|
|
2015-09-04 12:31:19 +09:30
|
|
|
/*
|
|
|
|
* This file is part of Flarum.
|
|
|
|
*
|
2019-11-29 23:02:17 +00:00
|
|
|
* For detailed copyright and license information, please view the
|
|
|
|
* LICENSE file that was distributed with this source code.
|
2015-09-04 12:31:19 +09:30
|
|
|
*/
|
|
|
|
|
2021-05-04 14:57:29 -04:00
|
|
|
namespace Flarum\Mentions;
|
|
|
|
|
2020-12-08 17:15:52 +01:00
|
|
|
use Flarum\Api\Controller;
|
|
|
|
use Flarum\Api\Serializer\BasicPostSerializer;
|
2021-08-23 20:33:42 +01:00
|
|
|
use Flarum\Api\Serializer\BasicUserSerializer;
|
2022-11-05 19:29:01 +00:00
|
|
|
use Flarum\Api\Serializer\CurrentUserSerializer;
|
|
|
|
use Flarum\Api\Serializer\GroupSerializer;
|
2018-12-15 17:23:48 +01:00
|
|
|
use Flarum\Api\Serializer\PostSerializer;
|
2023-02-21 09:04:03 -06:00
|
|
|
use Flarum\Approval\Event\PostWasApproved;
|
2018-01-16 23:26:21 +01:00
|
|
|
use Flarum\Extend;
|
2022-11-05 19:29:01 +00:00
|
|
|
use Flarum\Group\Group;
|
2018-12-15 17:23:48 +01:00
|
|
|
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-04 14:57:29 -04:00
|
|
|
use Flarum\Post\Filter\PostFilterer;
|
2020-04-24 15:55:50 +02:00
|
|
|
use Flarum\Post\Post;
|
|
|
|
use Flarum\User\User;
|
2015-05-14 22:01:03 +09:30
|
|
|
|
2018-01-16 23:26:21 +01:00
|
|
|
return [
|
2018-07-23 16:29:38 +02:00
|
|
|
(new Extend\Frontend('forum'))
|
2018-06-20 13:35:33 +09:30
|
|
|
->js(__DIR__.'/js/dist/forum.js')
|
2018-07-23 16:29:38 +02:00
|
|
|
->css(__DIR__.'/less/forum.less'),
|
2018-06-20 13:35:33 +09:30
|
|
|
|
2021-04-21 10:58:54 +01:00
|
|
|
(new Extend\Frontend('admin'))
|
|
|
|
->js(__DIR__.'/js/dist/admin.js'),
|
|
|
|
|
2018-12-15 12:06:08 +01:00
|
|
|
(new Extend\Formatter)
|
2021-03-01 23:26:35 -05:00
|
|
|
->configure(ConfigureMentions::class)
|
|
|
|
->render(Formatter\FormatPostMentions::class)
|
2021-04-21 10:58:54 +01:00
|
|
|
->render(Formatter\FormatUserMentions::class)
|
2022-11-05 19:29:01 +00:00
|
|
|
->render(Formatter\FormatGroupMentions::class)
|
2021-04-21 10:58:54 +01:00
|
|
|
->unparse(Formatter\UnparsePostMentions::class)
|
2022-11-05 19:29:01 +00:00
|
|
|
->unparse(Formatter\UnparseUserMentions::class)
|
|
|
|
->parse(Formatter\CheckPermissions::class),
|
2018-12-15 12:06:08 +01:00
|
|
|
|
2020-04-24 15:55:50 +02: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')
|
2022-11-05 19:29:01 +00:00
|
|
|
->belongsToMany('mentionsUsers', User::class, 'post_mentions_user', 'post_id', 'mentions_user_id')
|
|
|
|
->belongsToMany('mentionsGroups', Group::class, 'post_mentions_group', 'post_id', 'mentions_group_id'),
|
2020-04-24 15:55:50 +02:00
|
|
|
|
2020-06-19 22:27:37 -04:00
|
|
|
new Extend\Locales(__DIR__.'/locale'),
|
|
|
|
|
2020-07-17 12:10:47 +02:00
|
|
|
(new Extend\View)
|
|
|
|
->namespace('flarum-mentions', __DIR__.'/views'),
|
|
|
|
|
2020-10-31 23:43:02 +01:00
|
|
|
(new Extend\Notification())
|
2022-11-05 19:29:01 +00:00
|
|
|
->type(Notification\PostMentionedBlueprint::class, PostSerializer::class, ['alert'])
|
|
|
|
->type(Notification\UserMentionedBlueprint::class, PostSerializer::class, ['alert'])
|
|
|
|
->type(Notification\GroupMentionedBlueprint::class, PostSerializer::class, ['alert']),
|
2020-10-31 23:43:02 +01:00
|
|
|
|
2020-12-08 17:15:52 +01:00
|
|
|
(new Extend\ApiSerializer(BasicPostSerializer::class))
|
|
|
|
->hasMany('mentionedBy', BasicPostSerializer::class)
|
|
|
|
->hasMany('mentionsPosts', BasicPostSerializer::class)
|
2022-11-05 19:29:01 +00:00
|
|
|
->hasMany('mentionsUsers', BasicUserSerializer::class)
|
|
|
|
->hasMany('mentionsGroups', GroupSerializer::class),
|
2020-12-08 17:15:52 +01:00
|
|
|
|
|
|
|
(new Extend\ApiController(Controller\ShowDiscussionController::class))
|
2021-08-23 20:33:42 +01:00
|
|
|
->addInclude(['posts.mentionedBy', 'posts.mentionedBy.user', 'posts.mentionedBy.discussion'])
|
|
|
|
->load([
|
|
|
|
'posts.mentionsUsers', 'posts.mentionsPosts', 'posts.mentionsPosts.user', 'posts.mentionedBy',
|
|
|
|
'posts.mentionedBy.mentionsPosts', 'posts.mentionedBy.mentionsPosts.user', 'posts.mentionedBy.mentionsUsers',
|
2022-11-05 19:29:01 +00:00
|
|
|
'posts.mentionsGroups'
|
2021-08-23 20:33:42 +01:00
|
|
|
]),
|
|
|
|
|
|
|
|
(new Extend\ApiController(Controller\ListDiscussionsController::class))
|
|
|
|
->load([
|
2022-11-05 19:29:01 +00:00
|
|
|
'firstPost.mentionsUsers', 'firstPost.mentionsPosts', 'firstPost.mentionsPosts.user', 'firstPost.mentionsGroups',
|
|
|
|
'lastPost.mentionsUsers', 'lastPost.mentionsPosts', 'lastPost.mentionsPosts.user', 'lastPost.mentionsGroups'
|
2021-08-23 20:33:42 +01:00
|
|
|
]),
|
2020-12-08 17:15:52 +01:00
|
|
|
|
|
|
|
(new Extend\ApiController(Controller\ShowPostController::class))
|
|
|
|
->addInclude(['mentionedBy', 'mentionedBy.user', 'mentionedBy.discussion']),
|
2018-12-15 17:23:48 +01:00
|
|
|
|
2020-12-08 17:15:52 +01:00
|
|
|
(new Extend\ApiController(Controller\ListPostsController::class))
|
2021-08-23 20:33:42 +01:00
|
|
|
->addInclude(['mentionedBy', 'mentionedBy.user', 'mentionedBy.discussion'])
|
|
|
|
->load([
|
|
|
|
'mentionsUsers', 'mentionsPosts', 'mentionsPosts.user', 'mentionedBy',
|
|
|
|
'mentionedBy.mentionsPosts', 'mentionedBy.mentionsPosts.user', 'mentionedBy.mentionsUsers',
|
2022-11-05 19:29:01 +00:00
|
|
|
'mentionsGroups'
|
2021-08-23 20:33:42 +01:00
|
|
|
]),
|
2018-12-15 17:23:48 +01:00
|
|
|
|
2020-12-08 17:15:52 +01:00
|
|
|
(new Extend\ApiController(Controller\CreatePostController::class))
|
2022-11-05 19:29:01 +00:00
|
|
|
->addOptionalInclude('mentionsGroups'),
|
2015-10-11 13:02:57 +10:30
|
|
|
|
2021-08-23 20:33:42 +01:00
|
|
|
(new Extend\ApiController(Controller\UpdatePostController::class))
|
2022-11-05 19:29:01 +00:00
|
|
|
->addOptionalInclude('mentionsGroups'),
|
2021-08-23 20:33:42 +01:00
|
|
|
|
2020-12-08 17:15:52 +01:00
|
|
|
(new Extend\ApiController(Controller\AbstractSerializeController::class))
|
|
|
|
->prepareDataForSerialization(FilterVisiblePosts::class),
|
|
|
|
|
2021-04-21 10:58:54 +01:00
|
|
|
(new Extend\Settings)
|
|
|
|
->serializeToForum('allowUsernameMentionFormat', 'flarum-mentions.allow_username_format', 'boolval'),
|
|
|
|
|
2020-12-08 17:15:52 +01:00
|
|
|
(new Extend\Event())
|
|
|
|
->listen(Posted::class, Listener\UpdateMentionsMetadataWhenVisible::class)
|
|
|
|
->listen(Restored::class, Listener\UpdateMentionsMetadataWhenVisible::class)
|
|
|
|
->listen(Revised::class, Listener\UpdateMentionsMetadataWhenVisible::class)
|
2023-02-21 09:04:03 -06:00
|
|
|
->listen(PostWasApproved::class, Listener\UpdateMentionsMetadataWhenVisible::class)
|
2020-12-08 17:15:52 +01:00
|
|
|
->listen(Hidden::class, Listener\UpdateMentionsMetadataWhenInvisible::class)
|
2021-05-04 14:57:29 -04:00
|
|
|
->listen(Deleted::class, Listener\UpdateMentionsMetadataWhenInvisible::class),
|
|
|
|
|
|
|
|
(new Extend\Filter(PostFilterer::class))
|
|
|
|
->addFilter(Filter\MentionedFilter::class),
|
2022-11-05 19:29:01 +00:00
|
|
|
|
|
|
|
(new Extend\ApiSerializer(CurrentUserSerializer::class))
|
|
|
|
->attribute('canMentionGroups', function (CurrentUserSerializer $serializer, User $user, array $attributes): bool {
|
|
|
|
return $user->can('mentionGroups');
|
|
|
|
})
|
2018-01-16 23:26:21 +01:00
|
|
|
];
|