mirror of
https://github.com/flarum/core.git
synced 2025-07-29 20:50:28 +02:00
Update for composer branch
This commit is contained in:
2
extensions/pusher/.gitignore
vendored
2
extensions/pusher/.gitignore
vendored
@@ -2,3 +2,5 @@
|
|||||||
composer.phar
|
composer.phar
|
||||||
.DS_Store
|
.DS_Store
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
bower_components
|
||||||
|
node_modules
|
||||||
|
@@ -9,6 +9,11 @@
|
|||||||
* file that was distributed with this source code.
|
* 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);
|
||||||
|
};
|
@@ -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": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Flarum\\Pusher\\": "src/"
|
"Flarum\\Pusher\\": "src/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"require": {
|
"extra": {
|
||||||
"pusher/pusher-php-server": "^2.2"
|
"flarum-extension": {
|
||||||
},
|
"title": "Pusher",
|
||||||
"scripts": {
|
"icon": {
|
||||||
"style": "phpcs --standard=PSR2 -np src"
|
"image": "icon.png",
|
||||||
|
"backgroundSize": "55px 75px",
|
||||||
|
"backgroundPosition": "center",
|
||||||
|
"backgroundRepeat": "no-repeat",
|
||||||
|
"backgroundColor": "#40bad8",
|
||||||
|
"color": "#fff"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
62
extensions/pusher/composer.lock
generated
62
extensions/pusher/composer.lock
generated
@@ -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": []
|
|
||||||
}
|
|
@@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
BIN
extensions/pusher/icon.png
Normal file
BIN
extensions/pusher/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
3
extensions/pusher/js/.gitignore
vendored
3
extensions/pusher/js/.gitignore
vendored
@@ -1,3 +0,0 @@
|
|||||||
bower_components
|
|
||||||
node_modules
|
|
||||||
dist
|
|
@@ -2,6 +2,6 @@ var gulp = require('flarum-gulp');
|
|||||||
|
|
||||||
gulp({
|
gulp({
|
||||||
modules: {
|
modules: {
|
||||||
'pusher': 'src/**/*.js'
|
'flarum/pusher': 'src/**/*.js'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
88
extensions/pusher/js/admin/dist/extension.js
vendored
Normal file
88
extensions/pusher/js/admin/dist/extension.js
vendored
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
@@ -13,17 +13,17 @@ export default class PusherSettingsModal extends SettingsModal {
|
|||||||
return [
|
return [
|
||||||
<div className="Form-group">
|
<div className="Form-group">
|
||||||
<label>App ID</label>
|
<label>App ID</label>
|
||||||
<input className="FormControl" bidi={this.setting('pusher.app_id')}/>
|
<input className="FormControl" bidi={this.setting('flarum-pusher.app_id')}/>
|
||||||
</div>,
|
</div>,
|
||||||
|
|
||||||
<div className="Form-group">
|
<div className="Form-group">
|
||||||
<label>App Key</label>
|
<label>App Key</label>
|
||||||
<input className="FormControl" bidi={this.setting('pusher.app_key')}/>
|
<input className="FormControl" bidi={this.setting('flarum-pusher.app_key')}/>
|
||||||
</div>,
|
</div>,
|
||||||
|
|
||||||
<div className="Form-group">
|
<div className="Form-group">
|
||||||
<label>App Secret</label>
|
<label>App Secret</label>
|
||||||
<input className="FormControl" bidi={this.setting('pusher.app_secret')}/>
|
<input className="FormControl" bidi={this.setting('flarum-pusher.app_secret')}/>
|
||||||
</div>
|
</div>
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
import { extend } from 'flarum/extend';
|
import { extend } from 'flarum/extend';
|
||||||
import app from 'flarum/app';
|
import app from 'flarum/app';
|
||||||
|
|
||||||
import PusherSettingsModal from 'pusher/components/PusherSettingsModal';
|
import PusherSettingsModal from 'flarum/pusher/components/PusherSettingsModal';
|
||||||
|
|
||||||
app.initializers.add('pusher', app => {
|
app.initializers.add('flarum-pusher', app => {
|
||||||
app.extensionSettings.pusher = () => app.modal.show(new PusherSettingsModal());
|
app.extensionSettings['flarum-pusher'] = () => app.modal.show(new PusherSettingsModal());
|
||||||
});
|
});
|
||||||
|
@@ -2,6 +2,6 @@ var gulp = require('flarum-gulp');
|
|||||||
|
|
||||||
gulp({
|
gulp({
|
||||||
modules: {
|
modules: {
|
||||||
'pusher': 'src/**/*.js'
|
'flarum/pusher': 'src/**/*.js'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
177
extensions/pusher/js/forum/dist/extension.js
vendored
Normal file
177
extensions/pusher/js/forum/dist/extension.js
vendored
Normal file
@@ -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();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
@@ -7,7 +7,7 @@ import DiscussionPage from 'flarum/components/DiscussionPage';
|
|||||||
import IndexPage from 'flarum/components/IndexPage';
|
import IndexPage from 'flarum/components/IndexPage';
|
||||||
import Button from 'flarum/components/Button';
|
import Button from 'flarum/components/Button';
|
||||||
|
|
||||||
app.initializers.add('pusher', () => {
|
app.initializers.add('flarum-pusher', () => {
|
||||||
const loadPusher = m.deferred();
|
const loadPusher = m.deferred();
|
||||||
|
|
||||||
$.getScript('//js.pusher.com/3.0/pusher.min.js', () => {
|
$.getScript('//js.pusher.com/3.0/pusher.min.js', () => {
|
||||||
|
@@ -1,4 +0,0 @@
|
|||||||
pusher:
|
|
||||||
show_updated_discussions:
|
|
||||||
one: "Show {count} updated discussion"
|
|
||||||
other: "Show {count} updated discussions"
|
|
27
extensions/pusher/scripts/compile.sh
Executable file
27
extensions/pusher/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
|
@@ -8,36 +8,47 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Pusher\Api;
|
namespace Flarum\Pusher\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Api\Actions\Action;
|
use Flarum\Http\Controller\ControllerInterface;
|
||||||
use Flarum\Api\Request;
|
use Flarum\Settings\SettingsRepository;
|
||||||
use Flarum\Core\Settings\SettingsRepository;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Zend\Diactoros\Response\JsonResponse;
|
|
||||||
use Zend\Diactoros\Response\EmptyResponse;
|
|
||||||
use Pusher;
|
use Pusher;
|
||||||
|
use Zend\Diactoros\Response\EmptyResponse;
|
||||||
|
use Zend\Diactoros\Response\JsonResponse;
|
||||||
|
|
||||||
class AuthAction implements Action
|
class AuthController implements ControllerInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var SettingsRepository
|
||||||
|
*/
|
||||||
protected $settings;
|
protected $settings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param SettingsRepository $settings
|
||||||
|
*/
|
||||||
public function __construct(SettingsRepository $settings)
|
public function __construct(SettingsRepository $settings)
|
||||||
{
|
{
|
||||||
$this->settings = $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(
|
$pusher = new Pusher(
|
||||||
$this->settings->get('pusher.app_key'),
|
$this->settings->get('pusher.app_key'),
|
||||||
$this->settings->get('pusher.app_secret'),
|
$this->settings->get('pusher.app_secret'),
|
||||||
$this->settings->get('pusher.app_id')
|
$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);
|
return new JsonResponse($payload);
|
||||||
}
|
}
|
@@ -1,24 +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\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');
|
|
||||||
}
|
|
||||||
}
|
|
48
extensions/pusher/src/Listener/AddClientAssets.php
Normal file
48
extensions/pusher/src/Listener/AddClientAssets.php
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<?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\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');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
61
extensions/pusher/src/Listener/AddPusherApi.php
Executable file
61
extensions/pusher/src/Listener/AddPusherApi.php
Executable file
@@ -0,0 +1,61 @@
|
|||||||
|
<?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\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);
|
||||||
|
}
|
||||||
|
}
|
@@ -8,31 +8,42 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Pusher\Listeners;
|
namespace Flarum\Pusher\Listener;
|
||||||
|
|
||||||
use Flarum\Events\PostWasPosted;
|
use Flarum\Core\Guest;
|
||||||
use Flarum\Events\NotificationWillBeSent;
|
use Flarum\Event\NotificationWillBeSent;
|
||||||
|
use Flarum\Event\PostWasPosted;
|
||||||
|
use Flarum\Settings\SettingsRepository;
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
use Flarum\Core\Settings\SettingsRepository;
|
|
||||||
use Flarum\Core\Users\Guest;
|
|
||||||
use Flarum\Core\Discussions\Discussion;
|
|
||||||
use Pusher;
|
use Pusher;
|
||||||
|
|
||||||
class PushNewPosts
|
class PushNewPosts
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var SettingsRepository
|
||||||
|
*/
|
||||||
protected $settings;
|
protected $settings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param SettingsRepository $settings
|
||||||
|
*/
|
||||||
public function __construct(SettingsRepository $settings)
|
public function __construct(SettingsRepository $settings)
|
||||||
{
|
{
|
||||||
$this->settings = $settings;
|
$this->settings = $settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Dispatcher $events
|
||||||
|
*/
|
||||||
public function subscribe(Dispatcher $events)
|
public function subscribe(Dispatcher $events)
|
||||||
{
|
{
|
||||||
$events->listen(PostWasPosted::class, [$this, 'pushNewPost']);
|
$events->listen(PostWasPosted::class, [$this, 'pushNewPost']);
|
||||||
$events->listen(NotificationWillBeSent::class, [$this, 'pushNotification']);
|
$events->listen(NotificationWillBeSent::class, [$this, 'pushNotification']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param PostWasPosted $event
|
||||||
|
*/
|
||||||
public function pushNewPost(PostWasPosted $event)
|
public function pushNewPost(PostWasPosted $event)
|
||||||
{
|
{
|
||||||
if ($event->post->isVisibleTo(new Guest)) {
|
if ($event->post->isVisibleTo(new Guest)) {
|
||||||
@@ -46,6 +57,9 @@ class PushNewPosts
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param NotificationWillBeSent $event
|
||||||
|
*/
|
||||||
public function pushNotification(NotificationWillBeSent $event)
|
public function pushNotification(NotificationWillBeSent $event)
|
||||||
{
|
{
|
||||||
$pusher = $this->getPusher();
|
$pusher = $this->getPusher();
|
||||||
@@ -58,12 +72,15 @@ class PushNewPosts
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Pusher
|
||||||
|
*/
|
||||||
protected function getPusher()
|
protected function getPusher()
|
||||||
{
|
{
|
||||||
return new Pusher(
|
return new Pusher(
|
||||||
$this->settings->get('pusher.app_key'),
|
$this->settings->get('flarum-pusher.app_key'),
|
||||||
$this->settings->get('pusher.app_secret'),
|
$this->settings->get('flarum-pusher.app_secret'),
|
||||||
$this->settings->get('pusher.app_id')
|
$this->settings->get('flarum-pusher.app_id')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,37 +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\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');
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,54 +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\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'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user