mirror of
https://github.com/flarum/core.git
synced 2025-08-22 16:14:00 +02:00
Add setting to automatically follow after reply. closes flarum/core#310
This commit is contained in:
55
extensions/subscriptions/src/Listener/FollowAfterReply.php
Normal file
55
extensions/subscriptions/src/Listener/FollowAfterReply.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Subscriptions\Listener;
|
||||
|
||||
use Flarum\Core\Access\AssertPermissionTrait;
|
||||
use Flarum\Event\ConfigureUserPreferences;
|
||||
use Flarum\Event\PostWasPosted;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
class FollowAfterReply
|
||||
{
|
||||
use AssertPermissionTrait;
|
||||
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(ConfigureUserPreferences::class, [$this, 'addUserPreference']);
|
||||
$events->listen(PostWasPosted::class, [$this, 'whenPostWasPosted']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConfigureUserPreferences $event
|
||||
*/
|
||||
public function addUserPreference(ConfigureUserPreferences $event)
|
||||
{
|
||||
$event->add('followAfterReply', 'boolval', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PostWasPosted $event
|
||||
*/
|
||||
public function whenPostWasPosted(PostWasPosted $event)
|
||||
{
|
||||
$actor = $event->actor;
|
||||
|
||||
if ($actor && $actor->exists && $actor->getPreference('followAfterReply')) {
|
||||
$this->assertRegistered($actor);
|
||||
|
||||
$state = $event->post->discussion->stateFor($actor);
|
||||
|
||||
$state->subscription = 'follow';
|
||||
$state->save();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user