2015-07-28 14:05:55 +08:00
|
|
|
<?php
|
|
|
|
|
2015-09-04 11:02:04 +08:00
|
|
|
/*
|
|
|
|
* This file is part of Flarum.
|
|
|
|
*
|
2019-11-30 07:02:10 +08:00
|
|
|
* For detailed copyright and license information, please view the
|
|
|
|
* LICENSE file that was distributed with this source code.
|
2015-09-04 11:02:04 +08:00
|
|
|
*/
|
|
|
|
|
2024-06-21 16:36:32 +08:00
|
|
|
use Flarum\Api\Context;
|
|
|
|
use Flarum\Api\Resource;
|
|
|
|
use Flarum\Api\Schema;
|
2020-12-09 03:21:00 +08:00
|
|
|
use Flarum\Discussion\Discussion;
|
2021-03-14 04:35:53 +08:00
|
|
|
use Flarum\Discussion\Search\DiscussionSearcher;
|
2018-01-17 06:18:41 +08:00
|
|
|
use Flarum\Extend;
|
2015-10-11 13:45:07 +08:00
|
|
|
use Flarum\Lock\Access;
|
2018-12-16 00:09:44 +08:00
|
|
|
use Flarum\Lock\Event\DiscussionWasLocked;
|
|
|
|
use Flarum\Lock\Event\DiscussionWasUnlocked;
|
2023-11-12 02:43:09 +08:00
|
|
|
use Flarum\Lock\Filter\LockedFilter;
|
2015-10-11 13:45:07 +08:00
|
|
|
use Flarum\Lock\Listener;
|
2018-12-16 00:09:44 +08:00
|
|
|
use Flarum\Lock\Notification\DiscussionLockedBlueprint;
|
|
|
|
use Flarum\Lock\Post\DiscussionLockedPost;
|
2023-11-12 02:43:09 +08:00
|
|
|
use Flarum\Search\Database\DatabaseSearchDriver;
|
2015-07-28 14:05:55 +08:00
|
|
|
|
2018-01-17 06:18:41 +08:00
|
|
|
return [
|
2018-07-23 22:28:59 +08:00
|
|
|
(new Extend\Frontend('forum'))
|
2018-06-20 12:05:19 +08:00
|
|
|
->js(__DIR__.'/js/dist/forum.js')
|
2018-07-23 22:28:59 +08:00
|
|
|
->css(__DIR__.'/less/forum.less'),
|
2018-06-20 12:05:19 +08:00
|
|
|
|
2018-07-23 22:28:59 +08:00
|
|
|
(new Extend\Frontend('admin'))
|
2018-06-20 12:05:19 +08:00
|
|
|
->js(__DIR__.'/js/dist/admin.js'),
|
|
|
|
|
2020-06-20 09:54:38 +08:00
|
|
|
new Extend\Locales(__DIR__.'/locale'),
|
|
|
|
|
2020-11-01 06:42:46 +08:00
|
|
|
(new Extend\Notification())
|
2024-06-21 16:36:32 +08:00
|
|
|
->type(DiscussionLockedBlueprint::class, ['alert']),
|
2020-11-01 06:42:46 +08:00
|
|
|
|
2023-01-20 04:49:38 +08:00
|
|
|
(new Extend\Model(Discussion::class))
|
|
|
|
->cast('is_locked', 'bool'),
|
|
|
|
|
2024-06-21 16:36:32 +08:00
|
|
|
(new Extend\ApiResource(Resource\DiscussionResource::class))
|
|
|
|
->fields(fn () => [
|
|
|
|
Schema\Boolean::make('isLocked')
|
|
|
|
->writable(fn (Discussion $discussion, Context $context) => $context->getActor()->can('lock', $discussion))
|
|
|
|
->set(function (Discussion $discussion, bool $isLocked, Context $context) {
|
|
|
|
$actor = $context->getActor();
|
|
|
|
|
|
|
|
if ($discussion->is_locked === $isLocked) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$discussion->is_locked = $isLocked;
|
|
|
|
|
|
|
|
$discussion->raise(
|
|
|
|
$discussion->is_locked
|
|
|
|
? new DiscussionWasLocked($discussion, $actor)
|
|
|
|
: new DiscussionWasUnlocked($discussion, $actor)
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
Schema\Boolean::make('canLock')
|
|
|
|
->get(fn (Discussion $discussion, Context $context) => $context->getActor()->can('lock', $discussion)),
|
|
|
|
]),
|
2018-12-16 00:09:44 +08:00
|
|
|
|
2020-12-09 03:21:00 +08:00
|
|
|
(new Extend\Post())
|
|
|
|
->type(DiscussionLockedPost::class),
|
2015-10-11 13:45:07 +08:00
|
|
|
|
2020-12-09 03:21:00 +08:00
|
|
|
(new Extend\Event())
|
|
|
|
->listen(DiscussionWasLocked::class, Listener\CreatePostWhenDiscussionIsLocked::class)
|
|
|
|
->listen(DiscussionWasUnlocked::class, Listener\CreatePostWhenDiscussionIsUnlocked::class),
|
|
|
|
|
2020-12-09 03:34:11 +08:00
|
|
|
(new Extend\Policy())
|
|
|
|
->modelPolicy(Discussion::class, Access\DiscussionPolicy::class),
|
|
|
|
|
2023-11-12 02:43:09 +08:00
|
|
|
(new Extend\SearchDriver(DatabaseSearchDriver::class))
|
|
|
|
->addFilter(DiscussionSearcher::class, LockedFilter::class),
|
2018-01-17 06:18:41 +08:00
|
|
|
];
|