Update to use new extenders

This commit is contained in:
Alexander Skvortsov 2021-03-13 15:15:11 -05:00
parent e17b088c20
commit 70cbe1d186
2 changed files with 11 additions and 13 deletions

View File

@ -13,12 +13,11 @@ use Flarum\Approval\Access;
use Flarum\Approval\Event\PostWasApproved;
use Flarum\Approval\Listener;
use Flarum\Discussion\Discussion;
use Flarum\Event\GetModelIsPrivate;
use Flarum\Extend;
use Flarum\Post\CommentPost;
use Flarum\Post\Event\Saving;
use Flarum\Post\Post;
use Flarum\Tags\Tag;
use Illuminate\Contracts\Events\Dispatcher;
return [
(new Extend\Frontend('forum'))
@ -64,7 +63,9 @@ return [
(new Extend\ModelVisibility(Discussion::class))
->scope(Access\ScopePrivateDiscussionVisibility::class, 'viewPrivate'),
function (Dispatcher $events) {
$events->listen(GetModelIsPrivate::class, [Listener\UnapproveNewContent::class, 'markUnapprovedContentAsPrivate']);
},
(new Extend\ModelPrivate(Discussion::class))
->checker([Listener\UnapproveNewContent::class, 'markUnapprovedContentAsPrivate']),
(new Extend\ModelPrivate(CommentPost::class))
->checker([Listener\UnapproveNewContent::class, 'markUnapprovedContentAsPrivate']),
];

View File

@ -10,10 +10,9 @@
namespace Flarum\Approval\Listener;
use Flarum\Discussion\Discussion;
use Flarum\Event\GetModelIsPrivate;
use Flarum\Flags\Flag;
use Flarum\Post\CommentPost;
use Flarum\Post\Event\Saving;
use Flarum\Post\Post;
class UnapproveNewContent
{
@ -55,15 +54,13 @@ class UnapproveNewContent
}
/**
* @param GetModelIsPrivate $event
* @param Discussion|CommentPost $instance
* @return bool|null
*/
public static function markUnapprovedContentAsPrivate(GetModelIsPrivate $event)
public static function markUnapprovedContentAsPrivate($instance)
{
if ($event->model instanceof Post || $event->model instanceof Discussion) {
if (! $event->model->is_approved) {
if (! $instance->is_approved) {
return true;
}
}
}
}