-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: send notifications of a new reply when post is approved (#3656)
* test(subscriptions): approved reply sends out notifications to users Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * feat: send notifications when a post is approved The code in approval was extracted into a listener because no matter what listeners are always executed before subscribers even if the extension is set to load before. Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>
- Loading branch information
Showing
3 changed files
with
42 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* For detailed copyright and license information, please view the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Flarum\Approval\Listener; | ||
|
||
use Flarum\Approval\Event\PostWasApproved; | ||
|
||
class UpdateDiscussionAfterPostApproval | ||
{ | ||
public function handle(PostWasApproved $event) | ||
{ | ||
$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(); | ||
} | ||
} | ||
} |