diff --git a/extensions/pusher/.gitignore b/extensions/pusher/.gitignore
index a4f3b125e..0f98a63d8 100644
--- a/extensions/pusher/.gitignore
+++ b/extensions/pusher/.gitignore
@@ -2,3 +2,5 @@
composer.phar
.DS_Store
Thumbs.db
+bower_components
+node_modules
diff --git a/extensions/pusher/bootstrap.php b/extensions/pusher/bootstrap.php
index 1bb429114..5579f807e 100644
--- a/extensions/pusher/bootstrap.php
+++ b/extensions/pusher/bootstrap.php
@@ -9,6 +9,11 @@
* file that was distributed with this source code.
*/
-require __DIR__.'/vendor/autoload.php';
+use Flarum\Pusher\Listener;
+use Illuminate\Contracts\Events\Dispatcher;
-return 'Flarum\Pusher\Extension';
+return function (Dispatcher $events) {
+ $events->subscribe(Listener\AddClientAssets::class);
+ $events->subscribe(Listener\AddPusherApi::class);
+ $events->subscribe(Listener\PushNewPosts::class);
+};
\ No newline at end of file
diff --git a/extensions/pusher/composer.json b/extensions/pusher/composer.json
index 6574f31e8..d0f400620 100644
--- a/extensions/pusher/composer.json
+++ b/extensions/pusher/composer.json
@@ -1,13 +1,39 @@
{
+ "name": "flarum/pusher",
+ "description": "See new discussions and posts in real-time using Pusher.",
+ "type": "flarum-extension",
+ "keywords": ["discussion"],
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "Toby Zerner",
+ "email": "toby.zerner@gmail.com"
+ }
+ ],
+ "support": {
+ "issues": "https://github.com/flarum/core/issues",
+ "source": "https://github.com/flarum/pusher"
+ },
+ "require": {
+ "flarum/core": "^0.1.0-beta.3",
+ "pusher/pusher-php-server": "^2.2"
+ },
"autoload": {
"psr-4": {
"Flarum\\Pusher\\": "src/"
}
},
- "require": {
- "pusher/pusher-php-server": "^2.2"
- },
- "scripts": {
- "style": "phpcs --standard=PSR2 -np src"
+ "extra": {
+ "flarum-extension": {
+ "title": "Pusher",
+ "icon": {
+ "image": "icon.png",
+ "backgroundSize": "55px 75px",
+ "backgroundPosition": "center",
+ "backgroundRepeat": "no-repeat",
+ "backgroundColor": "#40bad8",
+ "color": "#fff"
+ }
+ }
}
}
diff --git a/extensions/pusher/composer.lock b/extensions/pusher/composer.lock
deleted file mode 100644
index c826d9e91..000000000
--- a/extensions/pusher/composer.lock
+++ /dev/null
@@ -1,62 +0,0 @@
-{
- "_readme": [
- "This file locks the dependencies of your project to a known state",
- "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
- "This file is @generated automatically"
- ],
- "hash": "158832e87d507a5310f1e3eed28d177f",
- "packages": [
- {
- "name": "pusher/pusher-php-server",
- "version": "v2.2.1",
- "source": {
- "type": "git",
- "url": "https://github.com/pusher/pusher-http-php.git",
- "reference": "79d755cc5d5b02b67779e2a40782fd6e3726657d"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/pusher/pusher-http-php/zipball/79d755cc5d5b02b67779e2a40782fd6e3726657d",
- "reference": "79d755cc5d5b02b67779e2a40782fd6e3726657d",
- "shasum": ""
- },
- "require": {
- "ext-curl": "*",
- "php": ">=5.2"
- },
- "require-dev": {
- "phpunit/phpunit": "~4"
- },
- "type": "library",
- "autoload": {
- "classmap": [
- "lib/"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "description": "Library for interacting with the Pusher REST API",
- "homepage": "https://github.com/pusher/pusher-php-server",
- "keywords": [
- "events",
- "php-pusher-server",
- "publish",
- "pusher",
- "realtime",
- "rest",
- "trigger"
- ],
- "time": "2015-05-13 11:01:46"
- }
- ],
- "packages-dev": [],
- "aliases": [],
- "minimum-stability": "stable",
- "stability-flags": [],
- "prefer-stable": false,
- "prefer-lowest": false,
- "platform": [],
- "platform-dev": []
-}
diff --git a/extensions/pusher/flarum.json b/extensions/pusher/flarum.json
deleted file mode 100644
index d004bc9a2..000000000
--- a/extensions/pusher/flarum.json
+++ /dev/null
@@ -1,25 +0,0 @@
-{
- "name": "pusher",
- "title": "Pusher",
- "description": "See new discussions and posts in real-time using Pusher.",
- "keywords": [],
- "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/pusher",
- "issues": "https://github.com/flarum/core/issues"
- },
- "icon": {
- "name": "arrow-right",
- "backgroundColor": "#803A9D",
- "color": "#fff"
- }
-}
diff --git a/extensions/pusher/icon.png b/extensions/pusher/icon.png
new file mode 100644
index 000000000..ae7f49fec
Binary files /dev/null and b/extensions/pusher/icon.png differ
diff --git a/extensions/pusher/js/.gitignore b/extensions/pusher/js/.gitignore
deleted file mode 100644
index 372e20a51..000000000
--- a/extensions/pusher/js/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-bower_components
-node_modules
-dist
diff --git a/extensions/pusher/js/admin/Gulpfile.js b/extensions/pusher/js/admin/Gulpfile.js
index c893c3cc3..f3700d54e 100644
--- a/extensions/pusher/js/admin/Gulpfile.js
+++ b/extensions/pusher/js/admin/Gulpfile.js
@@ -2,6 +2,6 @@ var gulp = require('flarum-gulp');
gulp({
modules: {
- 'pusher': 'src/**/*.js'
+ 'flarum/pusher': 'src/**/*.js'
}
});
diff --git a/extensions/pusher/js/admin/dist/extension.js b/extensions/pusher/js/admin/dist/extension.js
new file mode 100644
index 000000000..f940ff929
--- /dev/null
+++ b/extensions/pusher/js/admin/dist/extension.js
@@ -0,0 +1,88 @@
+System.register('flarum/pusher/main', ['flarum/extend', 'flarum/app', 'flarum/pusher/components/PusherSettingsModal'], function (_export) {
+ 'use strict';
+
+ var extend, app, PusherSettingsModal;
+ return {
+ setters: [function (_flarumExtend) {
+ extend = _flarumExtend.extend;
+ }, function (_flarumApp) {
+ app = _flarumApp['default'];
+ }, function (_flarumPusherComponentsPusherSettingsModal) {
+ PusherSettingsModal = _flarumPusherComponentsPusherSettingsModal['default'];
+ }],
+ execute: function () {
+
+ app.initializers.add('flarum-pusher', function (app) {
+ app.extensionSettings['flarum-pusher'] = function () {
+ return app.modal.show(new PusherSettingsModal());
+ };
+ });
+ }
+ };
+});;System.register('flarum/pusher/components/PusherSettingsModal', ['flarum/components/SettingsModal'], function (_export) {
+ 'use strict';
+
+ var SettingsModal, PusherSettingsModal;
+ return {
+ setters: [function (_flarumComponentsSettingsModal) {
+ SettingsModal = _flarumComponentsSettingsModal['default'];
+ }],
+ execute: function () {
+ PusherSettingsModal = (function (_SettingsModal) {
+ babelHelpers.inherits(PusherSettingsModal, _SettingsModal);
+
+ function PusherSettingsModal() {
+ babelHelpers.classCallCheck(this, PusherSettingsModal);
+ babelHelpers.get(Object.getPrototypeOf(PusherSettingsModal.prototype), 'constructor', this).apply(this, arguments);
+ }
+
+ babelHelpers.createClass(PusherSettingsModal, [{
+ key: 'className',
+ value: function className() {
+ return 'PusherSettingsModal Modal--small';
+ }
+ }, {
+ key: 'title',
+ value: function title() {
+ return 'Pusher Settings';
+ }
+ }, {
+ key: 'form',
+ value: function form() {
+ return [m(
+ 'div',
+ { className: 'Form-group' },
+ m(
+ 'label',
+ null,
+ 'App ID'
+ ),
+ m('input', { className: 'FormControl', bidi: this.setting('flarum-pusher.app_id') })
+ ), m(
+ 'div',
+ { className: 'Form-group' },
+ m(
+ 'label',
+ null,
+ 'App Key'
+ ),
+ m('input', { className: 'FormControl', bidi: this.setting('flarum-pusher.app_key') })
+ ), m(
+ 'div',
+ { className: 'Form-group' },
+ m(
+ 'label',
+ null,
+ 'App Secret'
+ ),
+ m('input', { className: 'FormControl', bidi: this.setting('flarum-pusher.app_secret') })
+ )];
+ }
+ }]);
+ return PusherSettingsModal;
+ })(SettingsModal);
+
+ _export('default', PusherSettingsModal);
+ }
+ };
+});
\ No newline at end of file
diff --git a/extensions/pusher/js/admin/src/components/PusherSettingsModal.js b/extensions/pusher/js/admin/src/components/PusherSettingsModal.js
index ce5b2e622..84278f8ac 100644
--- a/extensions/pusher/js/admin/src/components/PusherSettingsModal.js
+++ b/extensions/pusher/js/admin/src/components/PusherSettingsModal.js
@@ -13,17 +13,17 @@ export default class PusherSettingsModal extends SettingsModal {
return [
-
+
,
-
+
,
-
+
];
}
diff --git a/extensions/pusher/js/admin/src/main.js b/extensions/pusher/js/admin/src/main.js
index b52fc99c7..2cc655af8 100644
--- a/extensions/pusher/js/admin/src/main.js
+++ b/extensions/pusher/js/admin/src/main.js
@@ -1,8 +1,8 @@
import { extend } from 'flarum/extend';
import app from 'flarum/app';
-import PusherSettingsModal from 'pusher/components/PusherSettingsModal';
+import PusherSettingsModal from 'flarum/pusher/components/PusherSettingsModal';
-app.initializers.add('pusher', app => {
- app.extensionSettings.pusher = () => app.modal.show(new PusherSettingsModal());
+app.initializers.add('flarum-pusher', app => {
+ app.extensionSettings['flarum-pusher'] = () => app.modal.show(new PusherSettingsModal());
});
diff --git a/extensions/pusher/js/forum/Gulpfile.js b/extensions/pusher/js/forum/Gulpfile.js
index c893c3cc3..f3700d54e 100644
--- a/extensions/pusher/js/forum/Gulpfile.js
+++ b/extensions/pusher/js/forum/Gulpfile.js
@@ -2,6 +2,6 @@ var gulp = require('flarum-gulp');
gulp({
modules: {
- 'pusher': 'src/**/*.js'
+ 'flarum/pusher': 'src/**/*.js'
}
});
diff --git a/extensions/pusher/js/forum/dist/extension.js b/extensions/pusher/js/forum/dist/extension.js
new file mode 100644
index 000000000..d55c24c61
--- /dev/null
+++ b/extensions/pusher/js/forum/dist/extension.js
@@ -0,0 +1,177 @@
+System.register('flarum/pusher/main', ['flarum/extend', 'flarum/app', 'flarum/components/DiscussionList', 'flarum/components/DiscussionPage', 'flarum/components/IndexPage', 'flarum/components/Button'], function (_export) {
+ /*global Pusher*/
+
+ 'use strict';
+
+ var extend, app, DiscussionList, DiscussionPage, IndexPage, Button;
+ return {
+ setters: [function (_flarumExtend) {
+ extend = _flarumExtend.extend;
+ }, function (_flarumApp) {
+ app = _flarumApp['default'];
+ }, function (_flarumComponentsDiscussionList) {
+ DiscussionList = _flarumComponentsDiscussionList['default'];
+ }, function (_flarumComponentsDiscussionPage) {
+ DiscussionPage = _flarumComponentsDiscussionPage['default'];
+ }, function (_flarumComponentsIndexPage) {
+ IndexPage = _flarumComponentsIndexPage['default'];
+ }, function (_flarumComponentsButton) {
+ Button = _flarumComponentsButton['default'];
+ }],
+ execute: function () {
+
+ app.initializers.add('flarum-pusher', function () {
+ var loadPusher = m.deferred();
+
+ $.getScript('//js.pusher.com/3.0/pusher.min.js', function () {
+ var socket = new Pusher(app.forum.attribute('pusherKey'), {
+ authEndpoint: app.forum.attribute('apiUrl') + '/pusher/auth',
+ auth: {
+ headers: {
+ 'Authorization': 'Token ' + app.session.token
+ }
+ }
+ });
+
+ loadPusher.resolve({
+ main: socket.subscribe('public'),
+ user: app.session.user ? socket.subscribe('private-user' + app.session.user.id()) : null
+ });
+ });
+
+ app.pusher = loadPusher.promise;
+ app.pushedUpdates = [];
+
+ extend(DiscussionList.prototype, 'config', function (x, isInitialized, context) {
+ var _this = this;
+
+ if (isInitialized) return;
+
+ app.pusher.then(function (channels) {
+ channels.main.bind('newPost', function (data) {
+ var params = _this.props.params;
+
+ if (!params.q && !params.sort && !params.filter) {
+ if (params.tags) {
+ var tag = app.store.getBy('tags', 'slug', params.tags);
+
+ if (data.tagIds.indexOf(tag.id()) === -1) return;
+ }
+
+ var id = String(data.discussionId);
+
+ if ((!app.current.discussion || id !== app.current.discussion.id()) && app.pushedUpdates.indexOf(id) === -1) {
+ app.pushedUpdates.push(id);
+
+ if (app.current instanceof IndexPage) {
+ app.setTitleCount(app.pushedUpdates.length);
+ }
+
+ m.redraw();
+ }
+ }
+ });
+
+ extend(context, 'onunload', function () {
+ return channels.main.unbind();
+ });
+ });
+ });
+
+ extend(DiscussionList.prototype, 'view', function (vdom) {
+ var _this2 = this;
+
+ if (app.pushedUpdates) {
+ var count = app.pushedUpdates.length;
+
+ if (count) {
+ vdom.children.unshift(Button.component({
+ className: 'Button Button--block DiscussionList-update',
+ onclick: function onclick() {
+ _this2.refresh(false).then(function () {
+ _this2.loadingUpdated = false;
+ app.pushedUpdates = [];
+ app.setTitleCount(0);
+ m.redraw();
+ });
+ _this2.loadingUpdated = true;
+ },
+ loading: this.loadingUpdated,
+ children: app.trans('pusher.show_updated_discussions', { count: count })
+ }));
+ }
+ }
+ });
+
+ // Prevent any newly-created discussions from triggering the discussion list
+ // update button showing.
+ // TODO: Might be better pause the response to the push updates while the
+ // composer is loading? idk
+ extend(DiscussionList.prototype, 'addDiscussion', function (returned, discussion) {
+ var index = app.pushedUpdates.indexOf(discussion.id());
+
+ if (index !== -1) {
+ app.pushedUpdates.splice(index, 1);
+ }
+
+ if (app.current instanceof IndexPage) {
+ app.setTitleCount(app.pushedUpdates.length);
+ }
+
+ m.redraw();
+ });
+
+ extend(DiscussionPage.prototype, 'config', function (x, isInitialized, context) {
+ var _this3 = this;
+
+ if (isInitialized) return;
+
+ app.pusher.then(function (channels) {
+ channels.main.bind('newPost', function (data) {
+ var id = String(data.discussionId);
+
+ if (_this3.discussion && _this3.discussion.id() === id && _this3.stream) {
+ (function () {
+ var oldCount = _this3.discussion.commentsCount();
+
+ app.store.find('discussions', _this3.discussion.id()).then(function () {
+ _this3.stream.update();
+
+ if (!document.hasFocus()) {
+ app.setTitleCount(Math.max(0, _this3.discussion.commentsCount() - oldCount));
+
+ $(window).one('focus', function () {
+ return app.setTitleCount(0);
+ });
+ }
+ });
+ })();
+ }
+ });
+
+ extend(context, 'onunload', function () {
+ return channels.main.unbind();
+ });
+ });
+ });
+
+ extend(IndexPage.prototype, 'actionItems', function (items) {
+ delete items.refresh;
+ });
+
+ app.pusher.then(function (channels) {
+ if (channels.user) {
+ channels.user.bind('notification', function () {
+ app.session.user.pushAttributes({
+ unreadNotificationsCount: app.session.user.unreadNotificationsCount() + 1,
+ newNotificationsCount: app.session.user.newNotificationsCount() + 1
+ });
+ delete app.cache.notifications;
+ m.redraw();
+ });
+ }
+ });
+ });
+ }
+ };
+});
\ No newline at end of file
diff --git a/extensions/pusher/js/forum/src/main.js b/extensions/pusher/js/forum/src/main.js
index a20cdd5a8..9510d5ef5 100644
--- a/extensions/pusher/js/forum/src/main.js
+++ b/extensions/pusher/js/forum/src/main.js
@@ -7,7 +7,7 @@ import DiscussionPage from 'flarum/components/DiscussionPage';
import IndexPage from 'flarum/components/IndexPage';
import Button from 'flarum/components/Button';
-app.initializers.add('pusher', () => {
+app.initializers.add('flarum-pusher', () => {
const loadPusher = m.deferred();
$.getScript('//js.pusher.com/3.0/pusher.min.js', () => {
diff --git a/extensions/pusher/less/admin/extension.less b/extensions/pusher/less/admin/extension.less
deleted file mode 100644
index e69de29bb..000000000
diff --git a/extensions/pusher/locale/en.yml b/extensions/pusher/locale/en.yml
deleted file mode 100644
index 65131063b..000000000
--- a/extensions/pusher/locale/en.yml
+++ /dev/null
@@ -1,4 +0,0 @@
-pusher:
- show_updated_discussions:
- one: "Show {count} updated discussion"
- other: "Show {count} updated discussions"
diff --git a/extensions/pusher/scripts/compile.sh b/extensions/pusher/scripts/compile.sh
new file mode 100755
index 000000000..b0d8e8bd3
--- /dev/null
+++ b/extensions/pusher/scripts/compile.sh
@@ -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
diff --git a/extensions/pusher/src/Api/AuthAction.php b/extensions/pusher/src/Api/Controller/AuthController.php
similarity index 54%
rename from extensions/pusher/src/Api/AuthAction.php
rename to extensions/pusher/src/Api/Controller/AuthController.php
index cf7b8dc78..054e6b781 100644
--- a/extensions/pusher/src/Api/AuthAction.php
+++ b/extensions/pusher/src/Api/Controller/AuthController.php
@@ -8,36 +8,47 @@
* file that was distributed with this source code.
*/
-namespace Flarum\Pusher\Api;
+namespace Flarum\Pusher\Api\Controller;
-use Flarum\Api\Actions\Action;
-use Flarum\Api\Request;
-use Flarum\Core\Settings\SettingsRepository;
-use Zend\Diactoros\Response\JsonResponse;
-use Zend\Diactoros\Response\EmptyResponse;
+use Flarum\Http\Controller\ControllerInterface;
+use Flarum\Settings\SettingsRepository;
+use Psr\Http\Message\ServerRequestInterface;
use Pusher;
+use Zend\Diactoros\Response\EmptyResponse;
+use Zend\Diactoros\Response\JsonResponse;
-class AuthAction implements Action
+class AuthController implements ControllerInterface
{
+ /**
+ * @var SettingsRepository
+ */
protected $settings;
+ /**
+ * @param SettingsRepository $settings
+ */
public function __construct(SettingsRepository $settings)
{
$this->settings = $settings;
}
- public function handle(Request $request)
+ /**
+ * @param ServerRequestInterface $request
+ * @return EmptyResponse|JsonResponse
+ */
+ public function handle(ServerRequestInterface $request)
{
- $userChannel = 'private-user' . $request->actor->id;
+ $userChannel = 'private-user' . $request->getAttribute('actor')->id;
+ $body = $request->getParsedBody();
- if ($request->get('channel_name') === $userChannel) {
+ if (array_get($body, 'channel_name') === $userChannel) {
$pusher = new Pusher(
$this->settings->get('pusher.app_key'),
$this->settings->get('pusher.app_secret'),
$this->settings->get('pusher.app_id')
);
- $payload = json_decode($pusher->socket_auth($userChannel, $request->get('socket_id')), true);
+ $payload = json_decode($pusher->socket_auth($userChannel, array_get($body, 'socket_id')), true);
return new JsonResponse($payload);
}
diff --git a/extensions/pusher/src/Extension.php b/extensions/pusher/src/Extension.php
deleted file mode 100644
index fc1b3c742..000000000
--- a/extensions/pusher/src/Extension.php
+++ /dev/null
@@ -1,24 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Flarum\Pusher;
-
-use Flarum\Support\Extension as BaseExtension;
-use Illuminate\Events\Dispatcher;
-
-class Extension extends BaseExtension
-{
- public function listen(Dispatcher $events)
- {
- $events->subscribe('Flarum\Pusher\Listeners\AddClientAssets');
- $events->subscribe('Flarum\Pusher\Listeners\PushNewPosts');
- $events->subscribe('Flarum\Pusher\Listeners\AddApiAttributes');
- }
-}
diff --git a/extensions/pusher/src/Listener/AddClientAssets.php b/extensions/pusher/src/Listener/AddClientAssets.php
new file mode 100644
index 000000000..3bef0c107
--- /dev/null
+++ b/extensions/pusher/src/Listener/AddClientAssets.php
@@ -0,0 +1,48 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Flarum\Pusher\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/pusher/main');
+ $event->addTranslations('flarum-pusher.forum');
+ }
+
+ if ($event->isAdmin()) {
+ $event->addAssets([
+ __DIR__ . '/../../js/admin/dist/extension.js'
+ ]);
+ $event->addBootstrapper('flarum/pusher/main');
+ $event->addTranslations('flarum-pusher.admin');
+ }
+ }
+}
diff --git a/extensions/pusher/src/Listener/AddPusherApi.php b/extensions/pusher/src/Listener/AddPusherApi.php
new file mode 100755
index 000000000..b8f451cea
--- /dev/null
+++ b/extensions/pusher/src/Listener/AddPusherApi.php
@@ -0,0 +1,61 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Flarum\Pusher\Listener;
+
+use Flarum\Api\Serializer\ForumSerializer;
+use Flarum\Event\ConfigureApiRoutes;
+use Flarum\Event\PrepareApiAttributes;
+use Flarum\Pusher\Api\Controller\AuthController;
+use Flarum\Settings\SettingsRepository;
+use Illuminate\Contracts\Events\Dispatcher;
+
+class AddPusherApi
+{
+ /**
+ * @var SettingsRepository
+ */
+ protected $settings;
+
+ /**
+ * @param SettingsRepository $settings
+ */
+ public function __construct(SettingsRepository $settings)
+ {
+ $this->settings = $settings;
+ }
+
+ /**
+ * @param Dispatcher $events
+ */
+ public function subscribe(Dispatcher $events)
+ {
+ $events->listen(PrepareApiAttributes::class, [$this, 'addAttributes']);
+ $events->listen(ConfigureApiRoutes::class, [$this, 'addRoutes']);
+ }
+
+ /**
+ * @param PrepareApiAttributes $event
+ */
+ public function addAttributes(PrepareApiAttributes $event)
+ {
+ if ($event->isSerializer(ForumSerializer::class)) {
+ $event->attributes['pusherKey'] = $this->settings->get('flarum-pusher.app_key');
+ }
+ }
+
+ /**
+ * @param ConfigureApiRoutes $event
+ */
+ public function addRoutes(ConfigureApiRoutes $event)
+ {
+ $event->post('/pusher/auth', 'pusher.auth', AuthController::class);
+ }
+}
diff --git a/extensions/pusher/src/Listeners/PushNewPosts.php b/extensions/pusher/src/Listener/PushNewPosts.php
similarity index 70%
rename from extensions/pusher/src/Listeners/PushNewPosts.php
rename to extensions/pusher/src/Listener/PushNewPosts.php
index 38ca94b79..930293e2e 100644
--- a/extensions/pusher/src/Listeners/PushNewPosts.php
+++ b/extensions/pusher/src/Listener/PushNewPosts.php
@@ -8,31 +8,42 @@
* file that was distributed with this source code.
*/
-namespace Flarum\Pusher\Listeners;
+namespace Flarum\Pusher\Listener;
-use Flarum\Events\PostWasPosted;
-use Flarum\Events\NotificationWillBeSent;
+use Flarum\Core\Guest;
+use Flarum\Event\NotificationWillBeSent;
+use Flarum\Event\PostWasPosted;
+use Flarum\Settings\SettingsRepository;
use Illuminate\Contracts\Events\Dispatcher;
-use Flarum\Core\Settings\SettingsRepository;
-use Flarum\Core\Users\Guest;
-use Flarum\Core\Discussions\Discussion;
use Pusher;
class PushNewPosts
{
+ /**
+ * @var SettingsRepository
+ */
protected $settings;
+ /**
+ * @param SettingsRepository $settings
+ */
public function __construct(SettingsRepository $settings)
{
$this->settings = $settings;
}
+ /**
+ * @param Dispatcher $events
+ */
public function subscribe(Dispatcher $events)
{
$events->listen(PostWasPosted::class, [$this, 'pushNewPost']);
$events->listen(NotificationWillBeSent::class, [$this, 'pushNotification']);
}
+ /**
+ * @param PostWasPosted $event
+ */
public function pushNewPost(PostWasPosted $event)
{
if ($event->post->isVisibleTo(new Guest)) {
@@ -46,6 +57,9 @@ class PushNewPosts
}
}
+ /**
+ * @param NotificationWillBeSent $event
+ */
public function pushNotification(NotificationWillBeSent $event)
{
$pusher = $this->getPusher();
@@ -58,12 +72,15 @@ class PushNewPosts
}
}
+ /**
+ * @return Pusher
+ */
protected function getPusher()
{
return new Pusher(
- $this->settings->get('pusher.app_key'),
- $this->settings->get('pusher.app_secret'),
- $this->settings->get('pusher.app_id')
+ $this->settings->get('flarum-pusher.app_key'),
+ $this->settings->get('flarum-pusher.app_secret'),
+ $this->settings->get('flarum-pusher.app_id')
);
}
}
diff --git a/extensions/pusher/src/Listeners/AddApiAttributes.php b/extensions/pusher/src/Listeners/AddApiAttributes.php
deleted file mode 100755
index ca82b30cc..000000000
--- a/extensions/pusher/src/Listeners/AddApiAttributes.php
+++ /dev/null
@@ -1,37 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Flarum\Pusher\Listeners;
-
-use Flarum\Events\ApiAttributes;
-use Flarum\Events\RegisterApiRoutes;
-use Illuminate\Contracts\Events\Dispatcher;
-use Flarum\Api\Serializers\ForumSerializer;
-
-class AddApiAttributes
-{
- public function subscribe(Dispatcher $events)
- {
- $events->listen(ApiAttributes::class, [$this, 'addAttributes']);
- $events->listen(RegisterApiRoutes::class, [$this, 'addRoutes']);
- }
-
- public function addAttributes(ApiAttributes $event)
- {
- if ($event->serializer instanceof ForumSerializer) {
- $event->attributes['pusherKey'] = app('Flarum\Core\Settings\SettingsRepository')->get('pusher.app_key');
- }
- }
-
- public function addRoutes(RegisterApiRoutes $event)
- {
- $event->post('/pusher/auth', 'pusher.auth', 'Flarum\Pusher\Api\AuthAction');
- }
-}
diff --git a/extensions/pusher/src/Listeners/AddClientAssets.php b/extensions/pusher/src/Listeners/AddClientAssets.php
deleted file mode 100644
index 2b23d1990..000000000
--- a/extensions/pusher/src/Listeners/AddClientAssets.php
+++ /dev/null
@@ -1,54 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Flarum\Pusher\Listeners;
-
-use Flarum\Events\RegisterLocales;
-use Flarum\Events\BuildClientView;
-use Illuminate\Contracts\Events\Dispatcher;
-
-class AddClientAssets
-{
- public function subscribe(Dispatcher $events)
- {
- $events->listen(RegisterLocales::class, [$this, 'addLocale']);
- $events->listen(BuildClientView::class, [$this, 'addAssets']);
- }
-
- 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('pusher/main');
-
- $event->forumTranslations([
- 'pusher.show_updated_discussions'
- ]);
-
- $event->adminAssets([
- __DIR__.'/../../js/admin/dist/extension.js',
- __DIR__.'/../../less/admin/extension.less'
- ]);
-
- $event->adminBootstrapper('pusher/main');
-
- $event->adminTranslations([
- // 'pusher.hello_world'
- ]);
- }
-}