mirror of
https://github.com/flarum/framework.git
synced 2024-11-29 12:43:52 +08:00
Update for new Flags/Approval extensions
This commit is contained in:
parent
2fbbe0bea7
commit
5bb266ec3b
|
@ -1,25 +1,27 @@
|
||||||
import { extend } from 'flarum/extend';
|
import { extend, override } from 'flarum/extend';
|
||||||
import app from 'flarum/app';
|
import app from 'flarum/app';
|
||||||
|
|
||||||
import Button from 'flarum/components/Button';
|
|
||||||
import CommentPost from 'flarum/components/CommentPost';
|
|
||||||
import PostControls from 'flarum/utils/PostControls';
|
import PostControls from 'flarum/utils/PostControls';
|
||||||
|
import CommentPost from 'flarum/components/CommentPost';
|
||||||
|
|
||||||
app.initializers.add('akismet', () => {
|
app.initializers.add('akismet', () => {
|
||||||
extend(CommentPost.prototype, 'reportActionItems', function(items) {
|
extend(PostControls, 'destructiveControls', function(items, post) {
|
||||||
if (this.props.post.reports()[0].reporter() === 'Akismet') {
|
if (items.approve) {
|
||||||
items.add('notSpam',
|
const flags = post.flags();
|
||||||
<Button className="Button"
|
|
||||||
icon="check"
|
if (flags && flags.some(flag => flag.type() === 'akismet')) {
|
||||||
onclick={() => {
|
Object.assign(items.approve.content.props, {
|
||||||
this.dismissReport({akismet: 'ham'}).then(() => {
|
children: 'Not Spam'
|
||||||
PostControls.restoreAction.apply(this.props.post);
|
});
|
||||||
m.redraw();
|
}
|
||||||
});
|
|
||||||
}}>
|
|
||||||
Not Spam
|
|
||||||
</Button>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, -10); // set initializer priority to run after reports
|
|
||||||
|
override(CommentPost.prototype, 'flagReason', function(original, flag) {
|
||||||
|
if (flag.type() === 'akismet') {
|
||||||
|
return 'Akismet flagged as Spam';
|
||||||
|
}
|
||||||
|
|
||||||
|
return original(flag);
|
||||||
|
});
|
||||||
|
}, -20); // run after the approval extension
|
||||||
|
|
|
@ -16,14 +16,13 @@ use TijsVerkoyen\Akismet\Akismet;
|
||||||
use Flarum\Core;
|
use Flarum\Core;
|
||||||
use Flarum\Core\Posts\CommentPost;
|
use Flarum\Core\Posts\CommentPost;
|
||||||
use Flarum\Core\Settings\SettingsRepository;
|
use Flarum\Core\Settings\SettingsRepository;
|
||||||
use Flarum\Reports\Report;
|
use Flarum\Flags\Flag;
|
||||||
|
use Flarum\Approval\Events\PostWasApproved;
|
||||||
|
|
||||||
class ValidatePost
|
class ValidatePost
|
||||||
{
|
{
|
||||||
protected $settings;
|
protected $settings;
|
||||||
|
|
||||||
private $savingPost;
|
|
||||||
|
|
||||||
public function __construct(SettingsRepository $settings)
|
public function __construct(SettingsRepository $settings)
|
||||||
{
|
{
|
||||||
$this->settings = $settings;
|
$this->settings = $settings;
|
||||||
|
@ -32,6 +31,7 @@ class ValidatePost
|
||||||
public function subscribe(Dispatcher $events)
|
public function subscribe(Dispatcher $events)
|
||||||
{
|
{
|
||||||
$events->listen(PostWillBeSaved::class, [$this, 'validatePost']);
|
$events->listen(PostWillBeSaved::class, [$this, 'validatePost']);
|
||||||
|
$events->listen(PostWasApproved::class, [$this, 'submitHam']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validatePost(PostWillBeSaved $event)
|
public function validatePost(PostWillBeSaved $event)
|
||||||
|
@ -53,26 +53,26 @@ class ValidatePost
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($isSpam) {
|
if ($isSpam) {
|
||||||
$post->hide();
|
$post->is_approved = false;
|
||||||
|
|
||||||
$this->savingPost = $post;
|
// TODO:
|
||||||
|
// $post->is_spam = true;
|
||||||
|
|
||||||
CommentPost::saved(function (CommentPost $post) {
|
$post->afterSave(function ($post) {
|
||||||
if ($post !== $this->savingPost) {
|
$flag = new Flag;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$report = new Report;
|
$flag->post_id = $post->id;
|
||||||
|
$flag->type = 'akismet';
|
||||||
|
$flag->time = time();
|
||||||
|
|
||||||
$report->post_id = $post->id;
|
$flag->save();
|
||||||
$report->reporter = 'Akismet';
|
|
||||||
$report->reason = 'spam';
|
|
||||||
$report->time = time();
|
|
||||||
|
|
||||||
$report->save();
|
|
||||||
|
|
||||||
$this->savingPost = null;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function submitHam(PostWasApproved $event)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
// if ($post->is_spam)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user