Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add setting to automatically follow after reply. closes flarum/framew…
- Loading branch information
1 parent
e9739e9
commit 98276f9
Showing
5 changed files
with
110 additions
and
2 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,17 @@ | ||
import { extend } from 'flarum/extend'; | ||
import SettingsPage from 'flarum/components/SettingsPage'; | ||
import FieldSet from 'flarum/components/FieldSet'; | ||
import Switch from 'flarum/components/Switch'; | ||
import ItemList from 'flarum/utils/ItemList'; | ||
|
||
export default function() { | ||
extend(SettingsPage.prototype, 'notificationsItems', function(items) { | ||
items.add('followAfterReply', | ||
Switch.component({ | ||
children: app.translator.trans('flarum-subscriptions.forum.settings.forum_follow_after_reply_label'), | ||
state: this.user.preferences().followAfterReply, | ||
onchange: this.preferenceSaver('followAfterReply') | ||
}) | ||
); | ||
}); | ||
} |
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,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(); | ||
} | ||
} | ||
} |