Skip to content

Commit

Permalink
1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
KyrneDev committed Jul 12, 2021
1 parent 5ee870f commit 9f39872
Show file tree
Hide file tree
Showing 39 changed files with 10,949 additions and 5,016 deletions.
Binary file added .DS_Store
Binary file not shown.
17 changes: 5 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"type": "flarum-extension",
"license": "GPL-3.0-or-later",
"require": {
"flarum/core": "^0.1.0-beta-13",
"kyrne/ext-core": "*@dev"
"flarum/core": "^1.0.2"
},
"conflict": {
"flarum/mentions": "*"
Expand All @@ -30,16 +29,10 @@
"extra": {
"flarum-extension": {
"title": "Evergreen",
"icon": "fas fa-tree",
"info": {
"link": "https://discuss.flarum.org/d/24695-evergreen-comment-trees-for-flarum",
"location": "Flarum Commmunity"
},
"extra": {
"icon": "fab fa-github",
"link": "https://github.com/kyrnedev/evergreen",
"title": "Source",
"location": "Github"
"icon": {
"name": "fas fa-tree",
"background": "linear-gradient(90deg, rgba(2,0,36,1) 0%, rgba(224,64,251,1) 0%, rgba(33,150,243,1) 100%)",
"color": "#FFF"
}
}
}
Expand Down
97 changes: 65 additions & 32 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

namespace Kyrne\Evergreen;

use Flarum\Api\Controller;
use Flarum\Api\Event\Serializing;
use Flarum\Api\Event\WillSerializeData;
use Flarum\Api\Serializer\BasicPostSerializer;
use Flarum\Api\Serializer\PostSerializer;
use Flarum\Event\ConfigureNotificationTypes;
use Flarum\Event\ConfigurePostsQuery;
use Flarum\Event\ScopeModelVisibility;
use Flarum\Extend;
use Flarum\Formatter\Event\Rendering;
use Illuminate\Database\Eloquent\Builder;
use Kyrne\Evergreen\Api\Controller\ListTreePostController;
use Kyrne\Evergreen\ConfigureMentions;
use Kyrne\Evergreen\Notification\PostMentionedBlueprint;
use Kyrne\Evergreen\Notification\UserMentionedBlueprint;
use Flarum\Post\Event\Deleted;
Expand All @@ -22,10 +24,7 @@
use Flarum\Post\Event\Saving;
use Flarum\Post\Post;
use Flarum\User\User;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\View\Factory;
use Kyrne\Evergreen\Listener;
use Kyrne\ExtCore\Extend\AddKyrneCore;

return [
(new Extend\Frontend('forum'))
Expand All @@ -35,46 +34,80 @@
(new Extend\Routes('api'))
->get('/trees/{id}', 'evergeen.trees.get', ListTreePostController::class),
(new Extend\Event())
->listen(Serializing::class, Listener\InjectSettings::class)
->listen(Saving::class, Listener\SaveTreeList::class)
->listen(ConfigurePostsQuery::class, Listener\AddFilterByMentions::class)
->listen(WillSerializeData::class, Listener\FilterVisiblePosts::class)
->listen(Rendering::class, Listener\FormatPostMentions::class)
->listen(Rendering::class, Listener\FormatUserMentions::class)
->listen(ConfigureNotificationTypes::class, function (ConfigureNotificationTypes $event) {
$event->add(PostMentionedBlueprint::class, PostSerializer::class, ['alert']);
$event->add(UserMentionedBlueprint::class, PostSerializer::class, ['alert']);
})
->listen(ScopeModelVisibility::class, function(ScopeModelVisibility $event) {
$sql = $event->query->toSql();
->subscribe(Listener\HandleDeletions::class)
->listen(Deleted::class, Listener\UpdateMentionsMetadataWhenInvisible::class)
->listen(Hidden::class, Listener\UpdateMentionsMetadataWhenInvisible::class)
->listen(Posted::class, Listener\UpdateMentionsMetadataWhenVisible::class)
->listen(Restored::class, Listener\UpdateMentionsMetadataWhenVisible::class)
->listen(Revised::class, Listener\UpdateMentionsMetadataWhenVisible::class),

(new Extend\ModelVisibility(Post::class))
->scopeAll(function(User $actor, Builder $query, $ability) {
$sql = $query->toSql();
if (stripos($sql, 'from `posts') && !stripos($sql, 'update') && !stripos($sql, 'delete') && strpos($sql, 'id')) {
$event->query->where('reply_to', 0);
$query->where('reply_to', 0);
}
}),

new AddKyrneCore(),

(new Extend\Formatter)
->configure(ConfigureMentions::class),
(new Extend\Notification())
->type(PostMentionedBlueprint::class, PostSerializer::class, ['alert'])
->type(UserMentionedBlueprint::class, PostSerializer::class, ['alert']),

(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'),

function (Dispatcher $events, Factory $views) {
$events->subscribe(Listener\AddPostMentionedByRelationship::class);
$events->subscribe(Listener\HandleDeletions::class);
(new Extend\ApiSerializer(PostSerializer::class))
->attributes(function (PostSerializer $serializer, Post $post, array $attributes) {
$attributes['replyTo'] = (int) $post->reply_to;
$attributes['replyCount'] = (int) $post->reply_count;

return $attributes;
}),

(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']),

(new Extend\ApiController(Controller\ListPostsController::class))
->addInclude(['mentionedBy', 'mentionedBy.user', 'mentionedBy.discussion']),

(new Extend\ApiController(Controller\CreatePostController::class))
->addInclude(['mentionsPosts', 'mentionsPosts.mentionedBy']),

$events->listen(
[Deleted::class, Hidden::class],
Listener\UpdateMentionsMetadataWhenInvisible::class
);
(new Extend\ApiController(Controller\AbstractSerializeController::class))
->prepareDataForSerialization(FilterVisiblePosts::class),

$events->listen([Posted::class, Restored::class, Revised::class],
Listener\UpdateMentionsMetadataWhenVisible::class
);
(new Extend\Settings)
->serializeToForum('allowUsernameMentionFormat', 'flarum-mentions.allow_username_format', 'boolval'),

(new Extend\Formatter)
->configure(ConfigureMentions::class)
->render(Formatter\FormatPostMentions::class)
->render(Formatter\FormatUserMentions::class)
->unparse(Formatter\UnparsePostMentions::class)
->unparse(Formatter\UnparseUserMentions::class),

(new Extend\Formatter)
->configure(ConfigureMentions::class),

(new Extend\View())
->namespace('flarum-mentions', __DIR__ . '/views'),

(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'),

$views->addNamespace('flarum-mentions', __DIR__ . '/views');
}
(new Extend\Filter(PostFilterer::class))
->addFilter(Filter\MentionedFilter::class),
];
2 changes: 1 addition & 1 deletion js/dist/forum.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dist/forum.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 9f39872

Please sign in to comment.