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 Button from 'flarum/components/Button';
|
||||
import CommentPost from 'flarum/components/CommentPost';
|
||||
import PostControls from 'flarum/utils/PostControls';
|
||||
import CommentPost from 'flarum/components/CommentPost';
|
||||
|
||||
app.initializers.add('akismet', () => {
|
||||
extend(CommentPost.prototype, 'reportActionItems', function(items) {
|
||||
if (this.props.post.reports()[0].reporter() === 'Akismet') {
|
||||
items.add('notSpam',
|
||||
<Button className="Button"
|
||||
icon="check"
|
||||
onclick={() => {
|
||||
this.dismissReport({akismet: 'ham'}).then(() => {
|
||||
PostControls.restoreAction.apply(this.props.post);
|
||||
m.redraw();
|
||||
extend(PostControls, 'destructiveControls', function(items, post) {
|
||||
if (items.approve) {
|
||||
const flags = post.flags();
|
||||
|
||||
if (flags && flags.some(flag => flag.type() === 'akismet')) {
|
||||
Object.assign(items.approve.content.props, {
|
||||
children: 'Not Spam'
|
||||
});
|
||||
}}>
|
||||
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\Posts\CommentPost;
|
||||
use Flarum\Core\Settings\SettingsRepository;
|
||||
use Flarum\Reports\Report;
|
||||
use Flarum\Flags\Flag;
|
||||
use Flarum\Approval\Events\PostWasApproved;
|
||||
|
||||
class ValidatePost
|
||||
{
|
||||
protected $settings;
|
||||
|
||||
private $savingPost;
|
||||
|
||||
public function __construct(SettingsRepository $settings)
|
||||
{
|
||||
$this->settings = $settings;
|
||||
|
@ -32,6 +31,7 @@ class ValidatePost
|
|||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(PostWillBeSaved::class, [$this, 'validatePost']);
|
||||
$events->listen(PostWasApproved::class, [$this, 'submitHam']);
|
||||
}
|
||||
|
||||
public function validatePost(PostWillBeSaved $event)
|
||||
|
@ -53,26 +53,26 @@ class ValidatePost
|
|||
);
|
||||
|
||||
if ($isSpam) {
|
||||
$post->hide();
|
||||
$post->is_approved = false;
|
||||
|
||||
$this->savingPost = $post;
|
||||
// TODO:
|
||||
// $post->is_spam = true;
|
||||
|
||||
CommentPost::saved(function (CommentPost $post) {
|
||||
if ($post !== $this->savingPost) {
|
||||
return;
|
||||
}
|
||||
$post->afterSave(function ($post) {
|
||||
$flag = new Flag;
|
||||
|
||||
$report = new Report;
|
||||
$flag->post_id = $post->id;
|
||||
$flag->type = 'akismet';
|
||||
$flag->time = time();
|
||||
|
||||
$report->post_id = $post->id;
|
||||
$report->reporter = 'Akismet';
|
||||
$report->reason = 'spam';
|
||||
$report->time = time();
|
||||
|
||||
$report->save();
|
||||
|
||||
$this->savingPost = null;
|
||||
$flag->save();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function submitHam(PostWasApproved $event)
|
||||
{
|
||||
// TODO
|
||||
// if ($post->is_spam)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user