1
0
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:
Peter Mein
2016-03-07 23:01:34 +10:30
committed by Toby Zerner
parent bd6ef05bb1
commit 689d139ca3
5 changed files with 110 additions and 2 deletions

View 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();
}
}
}