mirror of
https://github.com/flarum/core.git
synced 2025-08-08 09:26:34 +02:00
Update for composer branch
This commit is contained in:
2
extensions/subscriptions/.gitignore
vendored
2
extensions/subscriptions/.gitignore
vendored
@@ -2,3 +2,5 @@
|
||||
composer.phar
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
bower_components
|
||||
node_modules
|
@@ -9,6 +9,16 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
require __DIR__.'/vendor/autoload.php';
|
||||
use Flarum\Subscriptions\Listener;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
|
||||
return 'Flarum\Subscriptions\Extension';
|
||||
return function (Dispatcher $events, Factory $views) {
|
||||
$events->subscribe(Listener\AddClientAssets::class);
|
||||
$events->subscribe(Listener\AddDiscussionSubscriptionAttribute::class);
|
||||
$events->subscribe(Listener\FilterDiscussionListBySubscription::class);
|
||||
$events->subscribe(Listener\SaveSubscriptionToDatabase::class);
|
||||
$events->subscribe(Listener\SendNotificationWhenReplyIsPosted::class);
|
||||
|
||||
$views->addNamespace('flarum-subscriptions', __DIR__.'/views');
|
||||
};
|
@@ -1,10 +1,34 @@
|
||||
{
|
||||
"name": "flarum/subscriptions",
|
||||
"description": "Allow users to follow discussions and receive notifications for new posts.",
|
||||
"type": "flarum-extension",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Toby Zerner",
|
||||
"email": "toby.zerner@gmail.com"
|
||||
}
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/flarum/core/issues",
|
||||
"source": "https://github.com/flarum/subscriptions"
|
||||
},
|
||||
"require": {
|
||||
"flarum/core": "^0.1.0-beta.3"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Flarum\\Subscriptions\\": "src/"
|
||||
"Flarum\\Tags\\": "src/"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"style": "phpcs --standard=PSR2 -np src"
|
||||
"extra": {
|
||||
"flarum-extension": {
|
||||
"title": "Subscriptions",
|
||||
"icon": {
|
||||
"name": "star",
|
||||
"backgroundColor": "#ffea7b",
|
||||
"color": "#de8e00"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,25 +0,0 @@
|
||||
{
|
||||
"name": "subscriptions",
|
||||
"title": "Subscriptions",
|
||||
"description": "Allow users to follow discussions and receive notifications for new posts.",
|
||||
"keywords": ["discussions"],
|
||||
"version": "0.1.0-beta.2",
|
||||
"author": {
|
||||
"name": "Toby Zerner",
|
||||
"email": "toby@flarum.org",
|
||||
"homepage": "http://tobyzerner.com"
|
||||
},
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"flarum": ">=0.1.0-beta.2"
|
||||
},
|
||||
"support": {
|
||||
"source": "https://github.com/flarum/subscriptions",
|
||||
"issues": "https://github.com/flarum/core/issues"
|
||||
},
|
||||
"icon": {
|
||||
"name": "star",
|
||||
"backgroundColor": "#ffea7b",
|
||||
"color": "#de8e00"
|
||||
}
|
||||
}
|
3
extensions/subscriptions/js/.gitignore
vendored
3
extensions/subscriptions/js/.gitignore
vendored
@@ -1,3 +0,0 @@
|
||||
bower_components
|
||||
node_modules
|
||||
dist
|
@@ -2,6 +2,6 @@ var gulp = require('flarum-gulp');
|
||||
|
||||
gulp({
|
||||
modules: {
|
||||
'subscriptions': 'src/**/*.js'
|
||||
'flarum/subscriptions': 'src/**/*.js'
|
||||
}
|
||||
});
|
||||
|
388
extensions/subscriptions/js/forum/dist/extension.js
vendored
Normal file
388
extensions/subscriptions/js/forum/dist/extension.js
vendored
Normal file
@@ -0,0 +1,388 @@
|
||||
System.register('flarum/subscriptions/addSubscriptionBadge', ['flarum/extend', 'flarum/models/Discussion', 'flarum/components/Badge'], function (_export) {
|
||||
'use strict';
|
||||
|
||||
var extend, Discussion, Badge;
|
||||
|
||||
_export('default', addSubscriptionBadge);
|
||||
|
||||
function addSubscriptionBadge() {
|
||||
extend(Discussion.prototype, 'badges', function (badges) {
|
||||
var badge = undefined;
|
||||
|
||||
switch (this.subscription()) {
|
||||
case 'follow':
|
||||
badge = Badge.component({
|
||||
label: app.trans('flarum-subscriptions.forum.following'),
|
||||
icon: 'star',
|
||||
type: 'following'
|
||||
});
|
||||
break;
|
||||
|
||||
case 'ignore':
|
||||
badge = Badge.component({
|
||||
label: app.trans('flarum-subscriptions.forum.ignoring'),
|
||||
icon: 'eye-slash',
|
||||
type: 'ignoring'
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
// no default
|
||||
}
|
||||
|
||||
if (badge) {
|
||||
badges.add('subscription', badge);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
setters: [function (_flarumExtend) {
|
||||
extend = _flarumExtend.extend;
|
||||
}, function (_flarumModelsDiscussion) {
|
||||
Discussion = _flarumModelsDiscussion['default'];
|
||||
}, function (_flarumComponentsBadge) {
|
||||
Badge = _flarumComponentsBadge['default'];
|
||||
}],
|
||||
execute: function () {}
|
||||
};
|
||||
});;System.register('flarum/subscriptions/addSubscriptionControls', ['flarum/extend', 'flarum/components/Button', 'flarum/components/DiscussionPage', 'flarum/utils/DiscussionControls', 'flarum/subscriptions/components/SubscriptionMenu'], function (_export) {
|
||||
'use strict';
|
||||
|
||||
var extend, Button, DiscussionPage, DiscussionControls, SubscriptionMenu;
|
||||
|
||||
_export('default', addSubscriptionControls);
|
||||
|
||||
function addSubscriptionControls() {
|
||||
extend(DiscussionControls, 'userControls', function (items, discussion, context) {
|
||||
if (app.session.user && !(context instanceof DiscussionPage)) {
|
||||
var states = {
|
||||
none: { label: app.trans('flarum-subscriptions.forum.follow'), icon: 'star', save: 'follow' },
|
||||
follow: { label: app.trans('flarum-subscriptions.forum.unfollow'), icon: 'star-o', save: false },
|
||||
ignore: { label: app.trans('flarum-subscriptions.forum.unignore'), icon: 'eye', save: false }
|
||||
};
|
||||
|
||||
var subscription = discussion.subscription() || 'none';
|
||||
|
||||
items.add('subscription', Button.component({
|
||||
children: states[subscription].label,
|
||||
icon: states[subscription].icon,
|
||||
onclick: discussion.save.bind(discussion, { subscription: states[subscription].save })
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
extend(DiscussionPage.prototype, 'sidebarItems', function (items) {
|
||||
if (app.session.user) {
|
||||
var discussion = this.discussion;
|
||||
|
||||
items.add('subscription', SubscriptionMenu.component({ discussion: discussion }));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
setters: [function (_flarumExtend) {
|
||||
extend = _flarumExtend.extend;
|
||||
}, function (_flarumComponentsButton) {
|
||||
Button = _flarumComponentsButton['default'];
|
||||
}, function (_flarumComponentsDiscussionPage) {
|
||||
DiscussionPage = _flarumComponentsDiscussionPage['default'];
|
||||
}, function (_flarumUtilsDiscussionControls) {
|
||||
DiscussionControls = _flarumUtilsDiscussionControls['default'];
|
||||
}, function (_flarumSubscriptionsComponentsSubscriptionMenu) {
|
||||
SubscriptionMenu = _flarumSubscriptionsComponentsSubscriptionMenu['default'];
|
||||
}],
|
||||
execute: function () {}
|
||||
};
|
||||
});;System.register('flarum/subscriptions/addSubscriptionFilter', ['flarum/extend', 'flarum/components/LinkButton', 'flarum/components/IndexPage', 'flarum/components/DiscussionList'], function (_export) {
|
||||
'use strict';
|
||||
|
||||
var extend, LinkButton, IndexPage, DiscussionList;
|
||||
|
||||
_export('default', addSubscriptionFilter);
|
||||
|
||||
function addSubscriptionFilter() {
|
||||
extend(IndexPage.prototype, 'navItems', function (items) {
|
||||
if (app.session.user) {
|
||||
var params = this.stickyParams();
|
||||
|
||||
params.filter = 'following';
|
||||
|
||||
items.add('following', LinkButton.component({
|
||||
href: app.route('index.filter', params),
|
||||
children: app.trans('flarum-subscriptions.forum.following'),
|
||||
icon: 'star'
|
||||
}), 50);
|
||||
}
|
||||
});
|
||||
|
||||
extend(DiscussionList.prototype, 'requestParams', function (params) {
|
||||
if (this.props.params.filter === 'following') {
|
||||
params.filter.q = (params.filter.q || '') + ' is:following';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
setters: [function (_flarumExtend) {
|
||||
extend = _flarumExtend.extend;
|
||||
}, function (_flarumComponentsLinkButton) {
|
||||
LinkButton = _flarumComponentsLinkButton['default'];
|
||||
}, function (_flarumComponentsIndexPage) {
|
||||
IndexPage = _flarumComponentsIndexPage['default'];
|
||||
}, function (_flarumComponentsDiscussionList) {
|
||||
DiscussionList = _flarumComponentsDiscussionList['default'];
|
||||
}],
|
||||
execute: function () {}
|
||||
};
|
||||
});;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) {
|
||||
'use strict';
|
||||
|
||||
var extend, app, Model, Discussion, NotificationGrid, addSubscriptionBadge, addSubscriptionControls, addSubscriptionFilter, NewPostNotification;
|
||||
return {
|
||||
setters: [function (_flarumExtend) {
|
||||
extend = _flarumExtend.extend;
|
||||
}, function (_flarumApp) {
|
||||
app = _flarumApp['default'];
|
||||
}, function (_flarumModel) {
|
||||
Model = _flarumModel['default'];
|
||||
}, function (_flarumModelsDiscussion) {
|
||||
Discussion = _flarumModelsDiscussion['default'];
|
||||
}, function (_flarumComponentsNotificationGrid) {
|
||||
NotificationGrid = _flarumComponentsNotificationGrid['default'];
|
||||
}, function (_flarumSubscriptionsAddSubscriptionBadge) {
|
||||
addSubscriptionBadge = _flarumSubscriptionsAddSubscriptionBadge['default'];
|
||||
}, function (_flarumSubscriptionsAddSubscriptionControls) {
|
||||
addSubscriptionControls = _flarumSubscriptionsAddSubscriptionControls['default'];
|
||||
}, function (_flarumSubscriptionsAddSubscriptionFilter) {
|
||||
addSubscriptionFilter = _flarumSubscriptionsAddSubscriptionFilter['default'];
|
||||
}, function (_flarumSubscriptionsComponentsNewPostNotification) {
|
||||
NewPostNotification = _flarumSubscriptionsComponentsNewPostNotification['default'];
|
||||
}],
|
||||
execute: function () {
|
||||
|
||||
app.initializers.add('subscriptions', function () {
|
||||
app.notificationComponents.newPost = NewPostNotification;
|
||||
|
||||
Discussion.prototype.subscription = Model.attribute('subscription');
|
||||
|
||||
addSubscriptionBadge();
|
||||
addSubscriptionControls();
|
||||
addSubscriptionFilter();
|
||||
|
||||
extend(NotificationGrid.prototype, 'notificationTypes', function (items) {
|
||||
items.add('newPost', {
|
||||
name: 'newPost',
|
||||
icon: 'star',
|
||||
label: app.trans('flarum-subscriptions.forum.notify_new_post')
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
});;System.register('flarum/subscriptions/components/NewPostNotification', ['flarum/components/Notification', 'flarum/helpers/username'], function (_export) {
|
||||
'use strict';
|
||||
|
||||
var Notification, username, NewPostNotification;
|
||||
return {
|
||||
setters: [function (_flarumComponentsNotification) {
|
||||
Notification = _flarumComponentsNotification['default'];
|
||||
}, function (_flarumHelpersUsername) {
|
||||
username = _flarumHelpersUsername['default'];
|
||||
}],
|
||||
execute: function () {
|
||||
NewPostNotification = (function (_Notification) {
|
||||
babelHelpers.inherits(NewPostNotification, _Notification);
|
||||
|
||||
function NewPostNotification() {
|
||||
babelHelpers.classCallCheck(this, NewPostNotification);
|
||||
babelHelpers.get(Object.getPrototypeOf(NewPostNotification.prototype), 'constructor', this).apply(this, arguments);
|
||||
}
|
||||
|
||||
babelHelpers.createClass(NewPostNotification, [{
|
||||
key: 'icon',
|
||||
value: function icon() {
|
||||
return 'star';
|
||||
}
|
||||
}, {
|
||||
key: 'href',
|
||||
value: function href() {
|
||||
var notification = this.props.notification;
|
||||
var discussion = notification.subject();
|
||||
var content = notification.content() || {};
|
||||
|
||||
return app.route.discussion(discussion, content.postNumber);
|
||||
}
|
||||
}, {
|
||||
key: 'content',
|
||||
value: function content() {
|
||||
return app.trans('flarum-subscriptions.forum.new_post_notification', { user: this.props.notification.sender() });
|
||||
}
|
||||
}]);
|
||||
return NewPostNotification;
|
||||
})(Notification);
|
||||
|
||||
_export('default', NewPostNotification);
|
||||
}
|
||||
};
|
||||
});;System.register('flarum/subscriptions/components/SubscriptionMenu', ['flarum/Component', 'flarum/components/Button', 'flarum/helpers/icon', 'flarum/subscriptions/components/SubscriptionMenuItem'], function (_export) {
|
||||
'use strict';
|
||||
|
||||
var Component, Button, icon, SubscriptionMenuItem, SubscriptionMenu;
|
||||
return {
|
||||
setters: [function (_flarumComponent) {
|
||||
Component = _flarumComponent['default'];
|
||||
}, function (_flarumComponentsButton) {
|
||||
Button = _flarumComponentsButton['default'];
|
||||
}, function (_flarumHelpersIcon) {
|
||||
icon = _flarumHelpersIcon['default'];
|
||||
}, function (_flarumSubscriptionsComponentsSubscriptionMenuItem) {
|
||||
SubscriptionMenuItem = _flarumSubscriptionsComponentsSubscriptionMenuItem['default'];
|
||||
}],
|
||||
execute: function () {
|
||||
SubscriptionMenu = (function (_Component) {
|
||||
babelHelpers.inherits(SubscriptionMenu, _Component);
|
||||
|
||||
function SubscriptionMenu() {
|
||||
babelHelpers.classCallCheck(this, SubscriptionMenu);
|
||||
babelHelpers.get(Object.getPrototypeOf(SubscriptionMenu.prototype), 'constructor', this).apply(this, arguments);
|
||||
}
|
||||
|
||||
babelHelpers.createClass(SubscriptionMenu, [{
|
||||
key: 'view',
|
||||
value: function view() {
|
||||
var _this = this;
|
||||
|
||||
var discussion = this.props.discussion;
|
||||
var subscription = discussion.subscription();
|
||||
|
||||
var buttonLabel = app.trans('flarum-subscriptions.forum.follow');
|
||||
var buttonIcon = 'star-o';
|
||||
var buttonClass = 'SubscriptionMenu-button--' + subscription;
|
||||
|
||||
switch (subscription) {
|
||||
case 'follow':
|
||||
buttonLabel = app.trans('flarum-subscriptions.forum.following');
|
||||
buttonIcon = 'star';
|
||||
break;
|
||||
|
||||
case 'ignore':
|
||||
buttonLabel = app.trans('flarum-subscriptions.forum.ignoring');
|
||||
buttonIcon = 'eye-slash';
|
||||
break;
|
||||
|
||||
default:
|
||||
// no default
|
||||
}
|
||||
|
||||
var options = [{
|
||||
subscription: false,
|
||||
icon: 'star-o',
|
||||
label: app.trans('flarum-subscriptions.forum.not_following'),
|
||||
description: app.trans('flarum-subscriptions.forum.not_following_description')
|
||||
}, {
|
||||
subscription: 'follow',
|
||||
icon: 'star',
|
||||
label: app.trans('flarum-subscriptions.forum.following'),
|
||||
description: app.trans('flarum-subscriptions.forum.following_description')
|
||||
}, {
|
||||
subscription: 'ignore',
|
||||
icon: 'eye-slash',
|
||||
label: app.trans('flarum-subscriptions.forum.ignoring'),
|
||||
description: app.trans('flarum-subscriptions.forum.ignoring_description')
|
||||
}];
|
||||
|
||||
return m(
|
||||
'div',
|
||||
{ className: 'Dropdown ButtonGroup SubscriptionMenu' },
|
||||
Button.component({
|
||||
className: 'Button SubscriptionMenu-button ' + buttonClass,
|
||||
icon: buttonIcon,
|
||||
children: buttonLabel,
|
||||
onclick: this.saveSubscription.bind(this, discussion, ['follow', 'ignore'].indexOf(subscription) !== -1 ? false : 'follow')
|
||||
}),
|
||||
m(
|
||||
'button',
|
||||
{ className: 'Dropdown-toggle Button Button--icon ' + buttonClass, 'data-toggle': 'dropdown' },
|
||||
icon('caret-down', { className: 'Button-icon' })
|
||||
),
|
||||
m(
|
||||
'ul',
|
||||
{ className: 'Dropdown-menu dropdown-menu Dropdown-menu--right' },
|
||||
options.map(function (props) {
|
||||
props.onclick = _this.saveSubscription.bind(_this, discussion, props.subscription);
|
||||
props.active = subscription === props.subscription;
|
||||
|
||||
return m(
|
||||
'li',
|
||||
null,
|
||||
SubscriptionMenuItem.component(props)
|
||||
);
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
}, {
|
||||
key: 'saveSubscription',
|
||||
value: function saveSubscription(discussion, subscription) {
|
||||
discussion.save({ subscription: subscription });
|
||||
}
|
||||
}]);
|
||||
return SubscriptionMenu;
|
||||
})(Component);
|
||||
|
||||
_export('default', SubscriptionMenu);
|
||||
}
|
||||
};
|
||||
});;System.register('flarum/subscriptions/components/SubscriptionMenuItem', ['flarum/Component', 'flarum/helpers/icon'], function (_export) {
|
||||
'use strict';
|
||||
|
||||
var Component, icon, SubscriptionMenuItem;
|
||||
return {
|
||||
setters: [function (_flarumComponent) {
|
||||
Component = _flarumComponent['default'];
|
||||
}, function (_flarumHelpersIcon) {
|
||||
icon = _flarumHelpersIcon['default'];
|
||||
}],
|
||||
execute: function () {
|
||||
SubscriptionMenuItem = (function (_Component) {
|
||||
babelHelpers.inherits(SubscriptionMenuItem, _Component);
|
||||
|
||||
function SubscriptionMenuItem() {
|
||||
babelHelpers.classCallCheck(this, SubscriptionMenuItem);
|
||||
babelHelpers.get(Object.getPrototypeOf(SubscriptionMenuItem.prototype), 'constructor', this).apply(this, arguments);
|
||||
}
|
||||
|
||||
babelHelpers.createClass(SubscriptionMenuItem, [{
|
||||
key: 'view',
|
||||
value: function view() {
|
||||
return m(
|
||||
'button',
|
||||
{ className: 'SubscriptionMenuItem hasIcon', onclick: this.props.onclick },
|
||||
this.props.active ? icon('check', { className: 'Button-icon' }) : '',
|
||||
m(
|
||||
'span',
|
||||
{ className: 'SubscriptionMenuItem-label' },
|
||||
icon(this.props.icon, { className: 'Button-icon' }),
|
||||
m(
|
||||
'strong',
|
||||
null,
|
||||
this.props.label
|
||||
),
|
||||
m(
|
||||
'span',
|
||||
{ className: 'SubscriptionMenuItem-description' },
|
||||
this.props.description
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}]);
|
||||
return SubscriptionMenuItem;
|
||||
})(Component);
|
||||
|
||||
_export('default', SubscriptionMenuItem);
|
||||
}
|
||||
};
|
||||
});
|
@@ -9,7 +9,7 @@ export default function addSubscriptionBadge() {
|
||||
switch (this.subscription()) {
|
||||
case 'follow':
|
||||
badge = Badge.component({
|
||||
label: app.trans('subscriptions.following'),
|
||||
label: app.trans('flarum-subscriptions.forum.following'),
|
||||
icon: 'star',
|
||||
type: 'following'
|
||||
});
|
||||
@@ -17,7 +17,7 @@ export default function addSubscriptionBadge() {
|
||||
|
||||
case 'ignore':
|
||||
badge = Badge.component({
|
||||
label: app.trans('subscriptions.ignoring'),
|
||||
label: app.trans('flarum-subscriptions.forum.ignoring'),
|
||||
icon: 'eye-slash',
|
||||
type: 'ignoring'
|
||||
});
|
||||
|
@@ -3,15 +3,15 @@ import Button from 'flarum/components/Button';
|
||||
import DiscussionPage from 'flarum/components/DiscussionPage';
|
||||
import DiscussionControls from 'flarum/utils/DiscussionControls';
|
||||
|
||||
import SubscriptionMenu from 'subscriptions/components/SubscriptionMenu';
|
||||
import SubscriptionMenu from 'flarum/subscriptions/components/SubscriptionMenu';
|
||||
|
||||
export default function addSubscriptionControls() {
|
||||
extend(DiscussionControls, 'userControls', function(items, discussion, context) {
|
||||
if (app.session.user && !(context instanceof DiscussionPage)) {
|
||||
const states = {
|
||||
none: {label: app.trans('subscriptions.follow'), icon: 'star', save: 'follow'},
|
||||
follow: {label: app.trans('subscriptions.unfollow'), icon: 'star-o', save: false},
|
||||
ignore: {label: app.trans('subscriptions.unignore'), icon: 'eye', save: false}
|
||||
none: {label: app.trans('flarum-subscriptions.forum.follow'), icon: 'star', save: 'follow'},
|
||||
follow: {label: app.trans('flarum-subscriptions.forum.unfollow'), icon: 'star-o', save: false},
|
||||
ignore: {label: app.trans('flarum-subscriptions.forum.unignore'), icon: 'eye', save: false}
|
||||
};
|
||||
|
||||
const subscription = discussion.subscription() || 'none';
|
||||
|
@@ -3,7 +3,7 @@ import LinkButton from 'flarum/components/LinkButton';
|
||||
import IndexPage from 'flarum/components/IndexPage';
|
||||
import DiscussionList from 'flarum/components/DiscussionList';
|
||||
|
||||
export default function addSubscriptionControls() {
|
||||
export default function addSubscriptionFilter() {
|
||||
extend(IndexPage.prototype, 'navItems', function(items) {
|
||||
if (app.session.user) {
|
||||
const params = this.stickyParams();
|
||||
@@ -12,7 +12,7 @@ export default function addSubscriptionControls() {
|
||||
|
||||
items.add('following', LinkButton.component({
|
||||
href: app.route('index.filter', params),
|
||||
children: app.trans('subscriptions.following'),
|
||||
children: app.trans('flarum-subscriptions.forum.following'),
|
||||
icon: 'star'
|
||||
}), 50);
|
||||
}
|
||||
|
@@ -15,6 +15,6 @@ export default class NewPostNotification extends Notification {
|
||||
}
|
||||
|
||||
content() {
|
||||
return app.trans('subscriptions.new_post_notification', {user: this.props.notification.sender()});
|
||||
return app.trans('flarum-subscriptions.forum.new_post_notification', {user: this.props.notification.sender()});
|
||||
}
|
||||
}
|
||||
|
@@ -2,25 +2,25 @@ import Component from 'flarum/Component';
|
||||
import Button from 'flarum/components/Button';
|
||||
import icon from 'flarum/helpers/icon';
|
||||
|
||||
import SubscriptionMenuItem from 'subscriptions/components/SubscriptionMenuItem';
|
||||
import SubscriptionMenuItem from 'flarum/subscriptions/components/SubscriptionMenuItem';
|
||||
|
||||
export default class SubscriptionMenu extends Component {
|
||||
view() {
|
||||
const discussion = this.props.discussion;
|
||||
const subscription = discussion.subscription();
|
||||
|
||||
let buttonLabel = app.trans('subscriptions.follow');
|
||||
let buttonLabel = app.trans('flarum-subscriptions.forum.follow');
|
||||
let buttonIcon = 'star-o';
|
||||
const buttonClass = 'SubscriptionMenu-button--' + subscription;
|
||||
|
||||
switch (subscription) {
|
||||
case 'follow':
|
||||
buttonLabel = app.trans('subscriptions.following');
|
||||
buttonLabel = app.trans('flarum-subscriptions.forum.following');
|
||||
buttonIcon = 'star';
|
||||
break;
|
||||
|
||||
case 'ignore':
|
||||
buttonLabel = app.trans('subscriptions.ignoring');
|
||||
buttonLabel = app.trans('flarum-subscriptions.forum.ignoring');
|
||||
buttonIcon = 'eye-slash';
|
||||
break;
|
||||
|
||||
@@ -32,20 +32,20 @@ export default class SubscriptionMenu extends Component {
|
||||
{
|
||||
subscription: false,
|
||||
icon: 'star-o',
|
||||
label: app.trans('subscriptions.not_following'),
|
||||
description: app.trans('subscriptions.not_following_description')
|
||||
label: app.trans('flarum-subscriptions.forum.not_following'),
|
||||
description: app.trans('flarum-subscriptions.forum.not_following_description')
|
||||
},
|
||||
{
|
||||
subscription: 'follow',
|
||||
icon: 'star',
|
||||
label: app.trans('subscriptions.following'),
|
||||
description: app.trans('subscriptions.following_description')
|
||||
label: app.trans('flarum-subscriptions.forum.following'),
|
||||
description: app.trans('flarum-subscriptions.forum.following_description')
|
||||
},
|
||||
{
|
||||
subscription: 'ignore',
|
||||
icon: 'eye-slash',
|
||||
label: app.trans('subscriptions.ignoring'),
|
||||
description: app.trans('subscriptions.ignoring_description')
|
||||
label: app.trans('flarum-subscriptions.forum.ignoring'),
|
||||
description: app.trans('flarum-subscriptions.forum.ignoring_description')
|
||||
}
|
||||
];
|
||||
|
||||
|
@@ -4,10 +4,10 @@ import Model from 'flarum/Model';
|
||||
import Discussion from 'flarum/models/Discussion';
|
||||
import NotificationGrid from 'flarum/components/NotificationGrid';
|
||||
|
||||
import addSubscriptionBadge from 'subscriptions/addSubscriptionBadge';
|
||||
import addSubscriptionControls from 'subscriptions/addSubscriptionControls';
|
||||
import addSubscriptionFilter from 'subscriptions/addSubscriptionFilter';
|
||||
import NewPostNotification from 'subscriptions/components/NewPostNotification';
|
||||
import addSubscriptionBadge from 'flarum/subscriptions/addSubscriptionBadge';
|
||||
import addSubscriptionControls from 'flarum/subscriptions/addSubscriptionControls';
|
||||
import addSubscriptionFilter from 'flarum/subscriptions/addSubscriptionFilter';
|
||||
import NewPostNotification from 'flarum/subscriptions/components/NewPostNotification';
|
||||
|
||||
app.initializers.add('subscriptions', function() {
|
||||
app.notificationComponents.newPost = NewPostNotification;
|
||||
@@ -22,7 +22,7 @@ app.initializers.add('subscriptions', function() {
|
||||
items.add('newPost', {
|
||||
name: 'newPost',
|
||||
icon: 'star',
|
||||
label: app.trans('subscriptions.notify_new_post')
|
||||
label: app.trans('flarum-subscriptions.forum.notify_new_post')
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -1,13 +0,0 @@
|
||||
subscriptions:
|
||||
following: Following
|
||||
ignoring: Ignoring
|
||||
follow: Follow
|
||||
unfollow: Unfollow
|
||||
ignore: Ignore
|
||||
notify_new_post: Someone posts in a discussion I'm following
|
||||
new_post_notification: "{username} posted"
|
||||
not_following: Not Following
|
||||
not_following_description: Be notified when @mentioned.
|
||||
following_description: Be notified of all replies.
|
||||
ignoring_description: Never be notified. Hide from the discussion list.
|
||||
unignore: Unignore
|
@@ -8,18 +8,13 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Migrations\Subscriptions;
|
||||
namespace Flarum\Subscriptions\Migration;
|
||||
|
||||
use Flarum\Database\AbstractMigration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Flarum\Migrations\Migration;
|
||||
|
||||
class AddSubscriptionToUsersDiscussionsTable extends Migration
|
||||
class AddSubscriptionToUsersDiscussionsTable extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$this->schema->table('users_discussions', function (Blueprint $table) {
|
||||
@@ -27,11 +22,6 @@ class AddSubscriptionToUsersDiscussionsTable extends Migration
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$this->schema->table('users_discussions', function (Blueprint $table) {
|
||||
|
27
extensions/subscriptions/scripts/compile.sh
Executable file
27
extensions/subscriptions/scripts/compile.sh
Executable file
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# This script compiles the extension so that it can be used in a Flarum
|
||||
# installation. It should be run from the root directory of the extension.
|
||||
|
||||
base=$PWD
|
||||
|
||||
cd "${base}/js"
|
||||
|
||||
if [ -f bower.json ]; then
|
||||
bower install
|
||||
fi
|
||||
|
||||
for app in forum admin; do
|
||||
cd "${base}/js"
|
||||
|
||||
if [ -d $app ]; then
|
||||
cd $app
|
||||
|
||||
if [ -f bower.json ]; then
|
||||
bower install
|
||||
fi
|
||||
|
||||
npm install
|
||||
gulp --production
|
||||
fi
|
||||
done
|
@@ -1,31 +0,0 @@
|
||||
<?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;
|
||||
|
||||
use Flarum\Support\Extension as BaseExtension;
|
||||
use Illuminate\Events\Dispatcher;
|
||||
|
||||
class Extension extends BaseExtension
|
||||
{
|
||||
public function listen(Dispatcher $events)
|
||||
{
|
||||
$events->subscribe('Flarum\Subscriptions\Listeners\AddClientAssets');
|
||||
$events->subscribe('Flarum\Subscriptions\Listeners\AddApiAttributes');
|
||||
$events->subscribe('Flarum\Subscriptions\Listeners\PersistSubscriptionData');
|
||||
$events->subscribe('Flarum\Subscriptions\Listeners\NotifyNewPosts');
|
||||
$events->subscribe('Flarum\Subscriptions\Listeners\HideIgnoredDiscussions');
|
||||
}
|
||||
|
||||
public function boot()
|
||||
{
|
||||
$this->loadViewsFrom(__DIR__.'/../views', 'subscriptions');
|
||||
}
|
||||
}
|
@@ -8,17 +8,23 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Subscriptions\Gambits;
|
||||
namespace Flarum\Subscriptions\Gambit;
|
||||
|
||||
use Flarum\Core\Search\Search;
|
||||
use Flarum\Core\Search\RegexGambit;
|
||||
use Flarum\Core\Search\AbstractRegexGambit;
|
||||
use Flarum\Core\Search\AbstractSearch;
|
||||
use Illuminate\Database\Query\Expression;
|
||||
|
||||
class SubscriptionGambit extends RegexGambit
|
||||
class SubscriptionGambit extends AbstractRegexGambit
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $pattern = 'is:(follow|ignor)(?:ing|ed)';
|
||||
|
||||
protected function conditions(Search $search, array $matches, $negate)
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function conditions(AbstractSearch $search, array $matches, $negate)
|
||||
{
|
||||
$actor = $search->getActor();
|
||||
|
40
extensions/subscriptions/src/Listener/AddClientAssets.php
Executable file
40
extensions/subscriptions/src/Listener/AddClientAssets.php
Executable file
@@ -0,0 +1,40 @@
|
||||
<?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\Event\ConfigureClientView;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
class AddClientAssets
|
||||
{
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(ConfigureClientView::class, [$this, 'addAssets']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConfigureClientView $event
|
||||
*/
|
||||
public function addAssets(ConfigureClientView $event)
|
||||
{
|
||||
if ($event->isForum()) {
|
||||
$event->addAssets([
|
||||
__DIR__.'/../../js/forum/dist/extension.js',
|
||||
__DIR__.'/../../less/forum/extension.less'
|
||||
]);
|
||||
$event->addBootstrapper('flarum/subscriptions/main');
|
||||
$event->addTranslations('flarum-subscriptions.forum');
|
||||
}
|
||||
}
|
||||
}
|
37
extensions/subscriptions/src/Listener/AddDiscussionSubscriptionAttribute.php
Executable file
37
extensions/subscriptions/src/Listener/AddDiscussionSubscriptionAttribute.php
Executable file
@@ -0,0 +1,37 @@
|
||||
<?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\Api\Serializer\DiscussionSerializer;
|
||||
use Flarum\Event\PrepareApiAttributes;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
class AddDiscussionSubscriptionAttribute
|
||||
{
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(PrepareApiAttributes::class, [$this, 'addAttributes']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PrepareApiAttributes $event
|
||||
*/
|
||||
public function addAttributes(PrepareApiAttributes $event)
|
||||
{
|
||||
if ($event->isSerializer(DiscussionSerializer::class)
|
||||
&& ($state = $event->model->state)) {
|
||||
$event->attributes['subscription'] = $state->subscription ?: false;
|
||||
}
|
||||
}
|
||||
}
|
65
extensions/subscriptions/src/Listener/FilterDiscussionListBySubscription.php
Executable file
65
extensions/subscriptions/src/Listener/FilterDiscussionListBySubscription.php
Executable file
@@ -0,0 +1,65 @@
|
||||
<?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\Event\ConfigureDiscussionGambits;
|
||||
use Flarum\Event\ConfigureDiscussionSearch;
|
||||
use Flarum\Event\ConfigureForumRoutes;
|
||||
use Flarum\Subscriptions\Gambit\SubscriptionGambit;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Database\Query\Expression;
|
||||
|
||||
class FilterDiscussionListBySubscription
|
||||
{
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(ConfigureDiscussionGambits::class, [$this, 'addGambit']);
|
||||
$events->listen(ConfigureDiscussionSearch::class, [$this, 'filterIgnored']);
|
||||
$events->listen(ConfigureForumRoutes::class, [$this, 'addRoutes']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConfigureDiscussionGambits $event
|
||||
*/
|
||||
public function addGambit(ConfigureDiscussionGambits $event)
|
||||
{
|
||||
$event->gambits->add(SubscriptionGambit::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConfigureDiscussionSearch $event
|
||||
*/
|
||||
public function filterIgnored(ConfigureDiscussionSearch $event)
|
||||
{
|
||||
if (! $event->criteria->query) {
|
||||
// might be better as `id IN (subquery)`?
|
||||
$actor = $event->search->getActor();
|
||||
$event->search->getQuery()->whereNotExists(function ($query) use ($actor) {
|
||||
$query->selectRaw(1)
|
||||
->from('users_discussions')
|
||||
->where('discussions.id', new Expression('discussion_id'))
|
||||
->where('user_id', $actor->id)
|
||||
->where('subscription', 'ignore');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConfigureForumRoutes $event
|
||||
*/
|
||||
public function addRoutes(ConfigureForumRoutes $event)
|
||||
{
|
||||
$event->get('/following', 'following');
|
||||
}
|
||||
}
|
@@ -8,18 +8,27 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Subscriptions\Listeners;
|
||||
namespace Flarum\Subscriptions\Listener;
|
||||
|
||||
use Flarum\Events\DiscussionWillBeSaved;
|
||||
use Flarum\Core\Exceptions\PermissionDeniedException;
|
||||
use Flarum\Core\Access\AssertPermissionTrait;
|
||||
use Flarum\Event\DiscussionWillBeSaved;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
class PersistSubscriptionData
|
||||
class SaveSubscriptionToDatabase
|
||||
{
|
||||
public function subscribe($events)
|
||||
use AssertPermissionTrait;
|
||||
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(DiscussionWillBeSaved::class, [$this, 'whenDiscussionWillBeSaved']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DiscussionWillBeSaved $event
|
||||
*/
|
||||
public function whenDiscussionWillBeSaved(DiscussionWillBeSaved $event)
|
||||
{
|
||||
$discussion = $event->discussion;
|
||||
@@ -29,9 +38,7 @@ class PersistSubscriptionData
|
||||
$actor = $event->actor;
|
||||
$subscription = $data['attributes']['subscription'];
|
||||
|
||||
if (! $actor->exists) {
|
||||
throw new PermissionDeniedException;
|
||||
}
|
||||
$this->assertRegistered($actor);
|
||||
|
||||
$state = $discussion->stateFor($actor);
|
||||
|
@@ -8,29 +8,40 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Subscriptions\Listeners;
|
||||
namespace Flarum\Subscriptions\Listener;
|
||||
|
||||
use Flarum\Subscriptions\Notifications\NewPostBlueprint;
|
||||
use Flarum\Events\RegisterNotificationTypes;
|
||||
use Flarum\Events\PostWasPosted;
|
||||
use Flarum\Events\PostWasHidden;
|
||||
use Flarum\Events\PostWasRestored;
|
||||
use Flarum\Events\PostWasDeleted;
|
||||
use Flarum\Core\Notifications\NotificationSyncer;
|
||||
use Flarum\Api\Serializer\DiscussionBasicSerializer;
|
||||
use Flarum\Core\Notification\NotificationSyncer;
|
||||
use Flarum\Core\Post;
|
||||
use Flarum\Event\ConfigureNotificationTypes;
|
||||
use Flarum\Event\PostWasDeleted;
|
||||
use Flarum\Event\PostWasHidden;
|
||||
use Flarum\Event\PostWasPosted;
|
||||
use Flarum\Event\PostWasRestored;
|
||||
use Flarum\Subscriptions\Notification\NewPostBlueprint;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
class NotifyNewPosts
|
||||
class SendNotificationWhenReplyIsPosted
|
||||
{
|
||||
/**
|
||||
* @var NotificationSyncer
|
||||
*/
|
||||
protected $notifications;
|
||||
|
||||
/**
|
||||
* @param NotificationSyncer $notifications
|
||||
*/
|
||||
public function __construct(NotificationSyncer $notifications)
|
||||
{
|
||||
$this->notifications = $notifications;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(RegisterNotificationTypes::class, [$this, 'addNotificationType']);
|
||||
$events->listen(ConfigureNotificationTypes::class, [$this, 'addNotificationType']);
|
||||
|
||||
// Register with '1' as priority so this runs before discussion metadata
|
||||
// is updated, as we need to compare the user's last read number to that
|
||||
@@ -41,15 +52,17 @@ class NotifyNewPosts
|
||||
$events->listen(PostWasDeleted::class, [$this, 'whenPostWasDeleted']);
|
||||
}
|
||||
|
||||
public function addNotificationType(RegisterNotificationTypes $event)
|
||||
/**
|
||||
* @param ConfigureNotificationTypes $event
|
||||
*/
|
||||
public function addNotificationType(ConfigureNotificationTypes $event)
|
||||
{
|
||||
$event->register(
|
||||
NewPostBlueprint::class,
|
||||
'Flarum\Api\Serializers\DiscussionBasicSerializer',
|
||||
['alert', 'email']
|
||||
);
|
||||
$event->add(NewPostBlueprint::class, DiscussionBasicSerializer::class, ['alert', 'email']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PostWasPosted $event
|
||||
*/
|
||||
public function whenPostWasPosted(PostWasPosted $event)
|
||||
{
|
||||
$post = $event->post;
|
||||
@@ -67,22 +80,35 @@ class NotifyNewPosts
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PostWasHidden $event
|
||||
*/
|
||||
public function whenPostWasHidden(PostWasHidden $event)
|
||||
{
|
||||
$this->notifications->delete($this->getNotification($event->post));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PostWasRestored $event
|
||||
*/
|
||||
public function whenPostWasRestored(PostWasRestored $event)
|
||||
{
|
||||
$this->notifications->restore($this->getNotification($event->post));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PostWasDeleted $event
|
||||
*/
|
||||
public function whenPostWasDeleted(PostWasDeleted $event)
|
||||
{
|
||||
$this->notifications->delete($this->getNotification($event->post));
|
||||
}
|
||||
|
||||
protected function getNotification($post)
|
||||
/**
|
||||
* @param Post $post
|
||||
* @return NewPostBlueprint
|
||||
*/
|
||||
protected function getNotification(Post $post)
|
||||
{
|
||||
return new NewPostBlueprint($post);
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
<?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\Listeners;
|
||||
|
||||
use Flarum\Events\ApiAttributes;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Flarum\Api\Serializers\DiscussionSerializer;
|
||||
|
||||
class AddApiAttributes
|
||||
{
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(ApiAttributes::class, [$this, 'addAttributes']);
|
||||
}
|
||||
|
||||
public function addAttributes(ApiAttributes $event)
|
||||
{
|
||||
if ($event->serializer instanceof DiscussionSerializer &&
|
||||
($state = $event->model->state)) {
|
||||
$event->attributes['subscription'] = $state->subscription ?: false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,61 +0,0 @@
|
||||
<?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\Listeners;
|
||||
|
||||
use Flarum\Events\RegisterLocales;
|
||||
use Flarum\Events\BuildClientView;
|
||||
use Flarum\Events\RegisterForumRoutes;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
class AddClientAssets
|
||||
{
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(RegisterLocales::class, [$this, 'addLocale']);
|
||||
$events->listen(BuildClientView::class, [$this, 'addAssets']);
|
||||
$events->listen(RegisterForumRoutes::class, [$this, 'addRoutes']);
|
||||
}
|
||||
|
||||
public function addLocale(RegisterLocales $event)
|
||||
{
|
||||
$event->addTranslations('en', __DIR__.'/../../locale/en.yml');
|
||||
}
|
||||
|
||||
public function addAssets(BuildClientView $event)
|
||||
{
|
||||
$event->forumAssets([
|
||||
__DIR__.'/../../js/forum/dist/extension.js',
|
||||
__DIR__.'/../../less/forum/extension.less'
|
||||
]);
|
||||
|
||||
$event->forumBootstrapper('subscriptions/main');
|
||||
|
||||
$event->forumTranslations([
|
||||
'subscriptions.following',
|
||||
'subscriptions.ignoring',
|
||||
'subscriptions.follow',
|
||||
'subscriptions.unfollow',
|
||||
'subscriptions.ignore',
|
||||
'subscriptions.notify_new_post',
|
||||
'subscriptions.new_post_notification',
|
||||
'subscriptions.not_following',
|
||||
'subscriptions.not_following_description',
|
||||
'subscriptions.following_description',
|
||||
'subscriptions.ignoring_description',
|
||||
'subscriptions.unignore'
|
||||
]);
|
||||
}
|
||||
|
||||
public function addRoutes(RegisterForumRoutes $event)
|
||||
{
|
||||
$event->get('/following', 'flarum.forum.following');
|
||||
}
|
||||
}
|
@@ -1,44 +0,0 @@
|
||||
<?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\Listeners;
|
||||
|
||||
use Flarum\Events\RegisterDiscussionGambits;
|
||||
use Flarum\Events\DiscussionSearchWillBePerformed;
|
||||
use Illuminate\Database\Query\Expression;
|
||||
|
||||
class HideIgnoredDiscussions
|
||||
{
|
||||
public function subscribe($events)
|
||||
{
|
||||
$events->listen(RegisterDiscussionGambits::class, [$this, 'addGambit']);
|
||||
$events->listen(DiscussionSearchWillBePerformed::class, [$this, 'filterIgnored']);
|
||||
}
|
||||
|
||||
public function addGambit(RegisterDiscussionGambits $event)
|
||||
{
|
||||
$event->gambits->add('Flarum\Subscriptions\Gambits\SubscriptionGambit');
|
||||
}
|
||||
|
||||
public function filterIgnored(DiscussionSearchWillBePerformed $event)
|
||||
{
|
||||
if (! $event->criteria->query) {
|
||||
// might be better as `id IN (subquery)`?
|
||||
$actor = $event->search->getActor();
|
||||
$event->search->getQuery()->whereNotExists(function ($query) use ($actor) {
|
||||
$query->selectRaw(1)
|
||||
->from('users_discussions')
|
||||
->where('discussions.id', new Expression('discussion_id'))
|
||||
->where('user_id', $actor->id)
|
||||
->where('subscription', 'ignore');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@@ -8,54 +8,81 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Subscriptions\Notifications;
|
||||
namespace Flarum\Subscriptions\Notification;
|
||||
|
||||
use Flarum\Core\Posts\Post;
|
||||
use Flarum\Core\Users\User;
|
||||
use Flarum\Core\Notifications\Blueprint;
|
||||
use Flarum\Core\Notifications\MailableBlueprint;
|
||||
use Flarum\Core\Discussion;
|
||||
use Flarum\Core\Post;
|
||||
use Flarum\Core\Notification\BlueprintInterface;
|
||||
use Flarum\Core\Notification\MailableInterface;
|
||||
|
||||
class NewPostBlueprint implements Blueprint, MailableBlueprint
|
||||
class NewPostBlueprint implements BlueprintInterface, MailableInterface
|
||||
{
|
||||
/**
|
||||
* @var Post
|
||||
*/
|
||||
public $post;
|
||||
|
||||
/**
|
||||
* @param Post $post
|
||||
*/
|
||||
public function __construct(Post $post)
|
||||
{
|
||||
$this->post = $post;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSubject()
|
||||
{
|
||||
return $this->post->discussion;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSender()
|
||||
{
|
||||
return $this->post->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
return ['postNumber' => (int) $this->post->number];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getEmailView()
|
||||
{
|
||||
return ['text' => 'subscriptions::emails.newPost'];
|
||||
return ['text' => 'flarum-subscriptions::emails.newPost'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getEmailSubject()
|
||||
{
|
||||
return '[New Post] '.$this->post->discussion->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getType()
|
||||
{
|
||||
return 'newPost';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubjectModel()
|
||||
{
|
||||
return 'Flarum\Core\Discussions\Discussion';
|
||||
return Discussion::class;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user