<commit_before><?php namespace Flarum\Mentions;

use Flarum\Support\ServiceProvider;
use Illuminate\Contracts\Events\Dispatcher;
use Flarum\Api\Actions\Discussions\ShowAction as DiscussionsShowAction;
use Flarum\Api\Actions\Posts\IndexAction as PostsIndexAction;
use Flarum\Api\Actions\Posts\ShowAction as PostsShowAction;
use Flarum\Api\Actions\Posts\CreateAction as PostsCreateAction;

class MentionsServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application events.
     *
     * @return void
     */
    public function boot(Dispatcher $events)
    {
        $events->subscribe('Flarum\Mentions\Handlers\PostMentionsMetadataUpdater');
        $events->subscribe('Flarum\Mentions\Handlers\UserMentionsMetadataUpdater');

        $this->forumAssets([
            __DIR__.'/../js/dist/extension.js',
            __DIR__.'/../less/mentions.less'
        ]);

        $this->relationship('Flarum\Core\Models\Post', function ($model) {
            return $model->belongsToMany('Flarum\Core\Models\Post', 'mentions_posts', 'mentions_id');
        }, 'mentionedBy');

        $this->serializeRelationship('Flarum\Api\Serializers\PostSerializer', 'hasMany', 'mentionedBy', 'Flarum\Api\Serializers\PostBasicSerializer');

        DiscussionsShowAction::$include['posts.mentionedBy'] = true;
        DiscussionsShowAction::$include['posts.mentionedBy.user'] = true;

        PostsShowAction::$include['mentionedBy'] = true;
        PostsShowAction::$include['mentionedBy.user'] = true;

        PostsIndexAction::$include['mentionedBy'] = true;
        PostsIndexAction::$include['mentionedBy.user'] = true;


        $this->relationship('Flarum\Core\Models\Post', function ($model) {
            return $model->belongsToMany('Flarum\Core\Models\Post', 'mentions_posts', 'post_id', 'mentions_id');
        }, 'mentionsPosts');

        $this->relationship('Flarum\Core\Models\Post', function ($model) {
            return $model->belongsToMany('Flarum\Core\Models\User', 'mentions_users', 'post_id', 'mentions_id');
        }, 'mentionsUsers');

        $this->serializeRelationship('Flarum\Api\Serializers\PostSerializer', 'hasMany', 'mentionsPosts', 'Flarum\Api\Serializers\PostBasicSerializer');
        $this->serializeRelationship('Flarum\Api\Serializers\PostSerializer', 'hasMany', 'mentionsUsers', 'Flarum\Api\Serializers\UserBasicSerializer');

        DiscussionsShowAction::$include['posts.mentionsPosts'] = true;
        DiscussionsShowAction::$include['posts.mentionsPosts.user'] = true;

        PostsCreateAction::$include['mentionsPosts'] = true;
        PostsCreateAction::$include['mentionsPosts.mentionedBy'] = true;

        DiscussionsShowAction::$include['posts.mentionsUsers'] = true;


        $this->formatter('postMentions', 'Flarum\Mentions\PostMentionsFormatter');
        $this->formatter('userMentions', 'Flarum\Mentions\UserMentionsFormatter');

        $this->notificationType('Flarum\Mentions\PostMentionedNotification', ['alert' => true]);
        $this->notificationType('Flarum\Mentions\UserMentionedNotification', ['alert' => true]);
    }
}<commit_msg>Update for new extension API<commit_after><?php namespace Flarum\Mentions;

use Flarum\Support\ServiceProvider;
use Flarum\Extend\EventSubscribers;
use Flarum\Extend\ForumAssets;
use Flarum\Extend\Relationship;
use Flarum\Extend\SerializeRelationship;
use Flarum\Extend\ApiInclude;
use Flarum\Extend\Formatter;
use Flarum\Extend\NotificationType;

class MentionsServiceProvider extends ServiceProvider
{
    public function boot()
    {
        $this->extend(
            new EventSubscribers([
                'Flarum\Mentions\Handlers\PostMentionsMetadataUpdater',
                'Flarum\Mentions\Handlers\UserMentionsMetadataUpdater'
            ]),

            new ForumAssets([
                __DIR__.'/../js/dist/extension.js',
                __DIR__.'/../less/mentions.less'
            ]),

            new Relationship('Flarum\Core\Models\Post', function ($model) {
                return $model->belongsToMany('Flarum\Core\Models\Post', 'mentions_posts', 'mentions_id');
            }, 'mentionedBy'),

            new Relationship('Flarum\Core\Models\Post', function ($model) {
                return $model->belongsToMany('Flarum\Core\Models\Post', 'mentions_posts', 'post_id', 'mentions_id');
            }, 'mentionsPosts'),

            new Relationship('Flarum\Core\Models\Post', function ($model) {
                return $model->belongsToMany('Flarum\Core\Models\User', 'mentions_users', 'post_id', 'mentions_id');
            }, 'mentionsUsers'),

            new SerializeRelationship('Flarum\Api\Serializers\PostSerializer', 'hasMany', 'mentionedBy', 'Flarum\Api\Serializers\PostBasicSerializer'),

            new SerializeRelationship('Flarum\Api\Serializers\PostSerializer', 'hasMany', 'mentionsPosts', 'Flarum\Api\Serializers\PostBasicSerializer'),

            new SerializeRelationship('Flarum\Api\Serializers\PostSerializer', 'hasMany', 'mentionsUsers', 'Flarum\Api\Serializers\UserBasicSerializer'),

            new ApiInclude('discussions.show', ['posts.mentionedBy', 'posts.mentionedBy.user', 'posts.mentionsPosts', 'posts.mentionsPosts.user', 'posts.mentionsUsers'], true),

            new ApiInclude(['posts.index', 'posts.show'], ['mentionedBy', 'mentionedBy.user'], true),

            new ApiInclude(['posts.create'], ['mentionsPosts', 'mentionsPosts.mentionedBy'], true),

            new Formatter('postMentions', 'Flarum\Mentions\PostMentionsFormatter'),

            new Formatter('userMentions', 'Flarum\Mentions\UserMentionsFormatter'),

            (new NotificationType('Flarum\Mentions\PostMentionedNotification'))->enableByDefault('alert'),

            (new NotificationType('Flarum\Mentions\UserMentionedNotification'))->enableByDefault('alert')
        );
    }
}
{'fraction_non_alphanumeric': 0.14217032967032966, 'fraction_numerical': 0.0, 'mean_word_length': 3.7902960526315788, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5808512', 'n_tokens_mistral': 1779, 'n_tokens_neox': 1653, 'n_words': 224}