mirror of
https://github.com/flarum/framework.git
synced 2024-11-25 17:57:04 +08:00
Add setting to automatically follow after reply. closes flarum/core#310
This commit is contained in:
parent
bd6ef05bb1
commit
689d139ca3
|
@ -19,6 +19,7 @@ return function (Dispatcher $events, Factory $views) {
|
||||||
$events->subscribe(Listener\FilterDiscussionListBySubscription::class);
|
$events->subscribe(Listener\FilterDiscussionListBySubscription::class);
|
||||||
$events->subscribe(Listener\SaveSubscriptionToDatabase::class);
|
$events->subscribe(Listener\SaveSubscriptionToDatabase::class);
|
||||||
$events->subscribe(Listener\SendNotificationWhenReplyIsPosted::class);
|
$events->subscribe(Listener\SendNotificationWhenReplyIsPosted::class);
|
||||||
|
$events->subscribe(Listener\FollowAfterReply::class);
|
||||||
|
|
||||||
$views->addNamespace('flarum-subscriptions', __DIR__.'/views');
|
$views->addNamespace('flarum-subscriptions', __DIR__.'/views');
|
||||||
};
|
};
|
||||||
|
|
|
@ -372,10 +372,10 @@ System.register('flarum/subscriptions/components/SubscriptionMenuItem', ['flarum
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});;
|
});;
|
||||||
System.register('flarum/subscriptions/main', ['flarum/extend', 'flarum/app', 'flarum/Model', 'flarum/models/Discussion', 'flarum/components/NotificationGrid', 'flarum/subscriptions/addSubscriptionBadge', 'flarum/subscriptions/addSubscriptionControls', 'flarum/subscriptions/addSubscriptionFilter', 'flarum/subscriptions/components/NewPostNotification'], function (_export) {
|
System.register('flarum/subscriptions/main', ['flarum/extend', 'flarum/app', 'flarum/Model', 'flarum/models/Discussion', 'flarum/components/NotificationGrid', 'flarum/subscriptions/addSubscriptionBadge', 'flarum/subscriptions/addSubscriptionControls', 'flarum/subscriptions/addSubscriptionFilter', 'flarum/subscriptions/addSubscriptionSettings', 'flarum/subscriptions/components/NewPostNotification'], function (_export) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var extend, app, Model, Discussion, NotificationGrid, addSubscriptionBadge, addSubscriptionControls, addSubscriptionFilter, NewPostNotification;
|
var extend, app, Model, Discussion, NotificationGrid, addSubscriptionBadge, addSubscriptionControls, addSubscriptionFilter, addSubscriptionSettings, NewPostNotification;
|
||||||
return {
|
return {
|
||||||
setters: [function (_flarumExtend) {
|
setters: [function (_flarumExtend) {
|
||||||
extend = _flarumExtend.extend;
|
extend = _flarumExtend.extend;
|
||||||
|
@ -393,6 +393,8 @@ System.register('flarum/subscriptions/main', ['flarum/extend', 'flarum/app', 'fl
|
||||||
addSubscriptionControls = _flarumSubscriptionsAddSubscriptionControls['default'];
|
addSubscriptionControls = _flarumSubscriptionsAddSubscriptionControls['default'];
|
||||||
}, function (_flarumSubscriptionsAddSubscriptionFilter) {
|
}, function (_flarumSubscriptionsAddSubscriptionFilter) {
|
||||||
addSubscriptionFilter = _flarumSubscriptionsAddSubscriptionFilter['default'];
|
addSubscriptionFilter = _flarumSubscriptionsAddSubscriptionFilter['default'];
|
||||||
|
}, function (_flarumSubscriptionsAddSubscriptionSettings) {
|
||||||
|
addSubscriptionSettings = _flarumSubscriptionsAddSubscriptionSettings['default'];
|
||||||
}, function (_flarumSubscriptionsComponentsNewPostNotification) {
|
}, function (_flarumSubscriptionsComponentsNewPostNotification) {
|
||||||
NewPostNotification = _flarumSubscriptionsComponentsNewPostNotification['default'];
|
NewPostNotification = _flarumSubscriptionsComponentsNewPostNotification['default'];
|
||||||
}],
|
}],
|
||||||
|
@ -406,6 +408,7 @@ System.register('flarum/subscriptions/main', ['flarum/extend', 'flarum/app', 'fl
|
||||||
addSubscriptionBadge();
|
addSubscriptionBadge();
|
||||||
addSubscriptionControls();
|
addSubscriptionControls();
|
||||||
addSubscriptionFilter();
|
addSubscriptionFilter();
|
||||||
|
addSubscriptionSettings();
|
||||||
|
|
||||||
extend(NotificationGrid.prototype, 'notificationTypes', function (items) {
|
extend(NotificationGrid.prototype, 'notificationTypes', function (items) {
|
||||||
items.add('newPost', {
|
items.add('newPost', {
|
||||||
|
@ -417,4 +420,33 @@ System.register('flarum/subscriptions/main', ['flarum/extend', 'flarum/app', 'fl
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
});;
|
||||||
|
System.register('flarum/subscriptions/addSubscriptionSettings', ['flarum/extend', 'flarum/components/SettingsPage', 'flarum/components/FieldSet', 'flarum/components/Switch', 'flarum/utils/ItemList'], function (_export) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var extend, SettingsPage, FieldSet, Switch, ItemList;
|
||||||
|
return {
|
||||||
|
setters: [function (_flarumExtend) {
|
||||||
|
extend = _flarumExtend.extend;
|
||||||
|
}, function (_flarumComponentsSettingsPage) {
|
||||||
|
SettingsPage = _flarumComponentsSettingsPage['default'];
|
||||||
|
}, function (_flarumComponentsFieldSet) {
|
||||||
|
FieldSet = _flarumComponentsFieldSet['default'];
|
||||||
|
}, function (_flarumComponentsSwitch) {
|
||||||
|
Switch = _flarumComponentsSwitch['default'];
|
||||||
|
}, function (_flarumUtilsItemList) {
|
||||||
|
ItemList = _flarumUtilsItemList['default'];
|
||||||
|
}],
|
||||||
|
execute: function () {
|
||||||
|
_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')
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
});
|
});
|
|
@ -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')
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
|
@ -7,6 +7,8 @@ import NotificationGrid from 'flarum/components/NotificationGrid';
|
||||||
import addSubscriptionBadge from 'flarum/subscriptions/addSubscriptionBadge';
|
import addSubscriptionBadge from 'flarum/subscriptions/addSubscriptionBadge';
|
||||||
import addSubscriptionControls from 'flarum/subscriptions/addSubscriptionControls';
|
import addSubscriptionControls from 'flarum/subscriptions/addSubscriptionControls';
|
||||||
import addSubscriptionFilter from 'flarum/subscriptions/addSubscriptionFilter';
|
import addSubscriptionFilter from 'flarum/subscriptions/addSubscriptionFilter';
|
||||||
|
import addSubscriptionSettings from 'flarum/subscriptions/addSubscriptionSettings';
|
||||||
|
|
||||||
import NewPostNotification from 'flarum/subscriptions/components/NewPostNotification';
|
import NewPostNotification from 'flarum/subscriptions/components/NewPostNotification';
|
||||||
|
|
||||||
app.initializers.add('subscriptions', function() {
|
app.initializers.add('subscriptions', function() {
|
||||||
|
@ -17,6 +19,7 @@ app.initializers.add('subscriptions', function() {
|
||||||
addSubscriptionBadge();
|
addSubscriptionBadge();
|
||||||
addSubscriptionControls();
|
addSubscriptionControls();
|
||||||
addSubscriptionFilter();
|
addSubscriptionFilter();
|
||||||
|
addSubscriptionSettings();
|
||||||
|
|
||||||
extend(NotificationGrid.prototype, 'notificationTypes', function(items) {
|
extend(NotificationGrid.prototype, 'notificationTypes', function(items) {
|
||||||
items.add('newPost', {
|
items.add('newPost', {
|
||||||
|
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user