Skip to content

Commit

Permalink
Revert "fix: Implement PostWasUnapproved event for all unapproved pos…
Browse files Browse the repository at this point in the history
…ts, hiding discussions for unapproved initial posts"

This reverts commit 3bbd1f7.
  • Loading branch information
rafaucau committed Nov 10, 2023
1 parent 3bbd1f7 commit d21770f
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 133 deletions.
4 changes: 2 additions & 2 deletions extensions/akismet/extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
use Flarum\Akismet\Listener;
use Flarum\Akismet\Provider\AkismetProvider;
use Flarum\Approval\Event\PostWasApproved;
use Flarum\Approval\Event\PostWasUnapproved;
use Flarum\Extend;
use Flarum\Post\Event\Hidden;
use Flarum\Post\Event\Saving;
use Flarum\Post\Post;

Expand All @@ -25,7 +25,7 @@
new Extend\Locales(__DIR__.'/locale'),

(new Extend\Event())
->listen(PostWasUnapproved::class, Listener\SubmitSpam::class)
->listen(Hidden::class, Listener\SubmitSpam::class)
->listen(PostWasApproved::class, Listener\SubmitHam::class)
->listen(Saving::class, Listener\ValidatePost::class),

Expand Down
4 changes: 2 additions & 2 deletions extensions/akismet/src/Listener/SubmitSpam.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Flarum\Akismet\Listener;

use Flarum\Akismet\Akismet;
use Flarum\Approval\Event\PostWasUnapproved;
use Flarum\Post\Event\Hidden;

class SubmitSpam
{
Expand All @@ -24,7 +24,7 @@ public function __construct(Akismet $akismet)
$this->akismet = $akismet;
}

public function handle(PostWasUnapproved $event)
public function handle(Hidden $event)
{
if (! $this->akismet->isConfigured()) {
return;
Expand Down
2 changes: 0 additions & 2 deletions extensions/approval/extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Flarum\Api\Serializer\PostSerializer;
use Flarum\Approval\Access;
use Flarum\Approval\Event\PostWasApproved;
use Flarum\Approval\Event\PostWasUnapproved;
use Flarum\Approval\Listener;
use Flarum\Discussion\Discussion;
use Flarum\Extend;
Expand Down Expand Up @@ -53,7 +52,6 @@

(new Extend\Event())
->listen(PostWasApproved::class, Listener\UpdateDiscussionAfterPostApproval::class)
->listen(PostWasUnapproved::class, Listener\UpdateDiscussionAfterPostUnapproval::class)
->subscribe(Listener\ApproveContent::class)
->subscribe(Listener\UnapproveNewContent::class),

Expand Down
38 changes: 0 additions & 38 deletions extensions/approval/src/Event/PostWasUnapproved.php

This file was deleted.

4 changes: 0 additions & 4 deletions extensions/approval/src/Listener/ApproveContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace Flarum\Approval\Listener;

use Flarum\Approval\Event\PostWasApproved;
use Flarum\Approval\Event\PostWasUnapproved;
use Flarum\Post\Event\Saving;
use Illuminate\Contracts\Events\Dispatcher;

Expand Down Expand Up @@ -38,13 +37,10 @@ public function approvePost(Saving $event)
}

if (! empty($isApproved)) {
// Set the post's approval status to true to clear any pending approval status, even if the post is hidden.
$post->is_approved = true;

if(! $post->hidden_at) {
$post->raise(new PostWasApproved($post, $event->actor));
} else {
$post->raise(new PostWasUnapproved($post, $event->actor));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,36 @@
namespace Flarum\Approval\Listener;

use Flarum\Approval\Event\PostWasApproved;
use Flarum\Approval\RefreshesDiscussionTrait;

class UpdateDiscussionAfterPostApproval
{
use RefreshesDiscussionTrait;

public function handle(PostWasApproved $event)
{
$this->refreshAndSaveDiscussion($event->post, function ($post, $discussion, $user) {
if ($post->number === 1) {
$discussion->is_approved = true;

$discussion->afterSave(function () use ($user) {
$user->refreshDiscussionCount();
});
}
});
$post = $event->post;
$discussion = $post->discussion;
$user = $discussion->user;

$discussion->refreshCommentCount();
$discussion->refreshLastPost();

if ($post->number === 1) {
$discussion->is_approved = true;

$discussion->afterSave(function () use ($user) {
$user->refreshDiscussionCount();
});
}

$discussion->save();

if ($discussion->user) {
$user->refreshCommentCount();
$user->save();
}

if ($post->user) {
$post->user->refreshCommentCount();
$post->user->save();
}
}
}

This file was deleted.

41 changes: 0 additions & 41 deletions extensions/approval/src/RefreshesDiscussionTrait.php

This file was deleted.

0 comments on commit d21770f

Please sign in to comment.