-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
FollowAfterReply.php
55 lines (46 loc) · 1.37 KB
/
FollowAfterReply.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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();
}
}
}