1
0
mirror of https://github.com/flarum/core.git synced 2025-07-30 21:20:24 +02:00

Initial commit

This commit is contained in:
Toby Zerner
2015-08-04 17:19:17 +09:30
commit 9b920daefa
23 changed files with 655 additions and 0 deletions

3
extensions/pusher/js/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
bower_components
node_modules
dist

View File

@@ -0,0 +1,7 @@
var gulp = require('flarum-gulp');
gulp({
modules: {
'pusher': 'src/**/*.js'
}
});

View File

@@ -0,0 +1,7 @@
{
"private": true,
"devDependencies": {
"gulp": "^3.8.11",
"flarum-gulp": "git+https://github.com/flarum/gulp.git"
}
}

View File

@@ -0,0 +1,71 @@
import Modal from 'flarum/components/Modal';
import Button from 'flarum/components/Button';
import saveConfig from 'flarum/utils/saveConfig';
export default class PusherSettingsModal extends Modal {
constructor(...args) {
super(...args);
this.appId = m.prop(app.config['pusher.app_id'] || '');
this.appKey = m.prop(app.config['pusher.app_key'] || '');
this.appSecret = m.prop(app.config['pusher.app_secret'] || '');
}
className() {
return 'PusherSettingsModal Modal--small';
}
title() {
return 'Pusher Settings';
}
content() {
return (
<div className="Modal-body">
<div className="Form">
<div className="Form-group">
<label>App ID</label>
<input className="FormControl" value={this.appId()} oninput={m.withAttr('value', this.appId)}/>
</div>
<div className="Form-group">
<label>App Key</label>
<input className="FormControl" value={this.appKey()} oninput={m.withAttr('value', this.appKey)}/>
</div>
<div className="Form-group">
<label>App Secret</label>
<input className="FormControl" value={this.appSecret()} oninput={m.withAttr('value', this.appSecret)}/>
</div>
<div className="Form-group">
{Button.component({
type: 'submit',
className: 'Button Button--primary PusherSettingsModal-save',
loading: this.loading,
children: 'Save Changes'
})}
</div>
</div>
</div>
);
}
onsubmit(e) {
e.preventDefault();
this.loading = true;
saveConfig({
'pusher.app_id': this.appId(),
'pusher.app_key': this.appKey(),
'pusher.app_secret': this.appSecret()
}).then(
() => this.hide(),
() => {
this.loading = false;
m.redraw();
}
);
}
}

View File

@@ -0,0 +1,8 @@
import { extend } from 'flarum/extend';
import app from 'flarum/app';
import PusherSettingsModal from 'pusher/components/PusherSettingsModal';
app.initializers.add('pusher', app => {
app.extensionSettings.pusher = () => app.modal.show(new PusherSettingsModal());
});

View File

@@ -0,0 +1,7 @@
var gulp = require('flarum-gulp');
gulp({
modules: {
'pusher': 'src/**/*.js'
}
});

View File

@@ -0,0 +1,7 @@
{
"private": true,
"devDependencies": {
"gulp": "^3.8.11",
"flarum-gulp": "git+https://github.com/flarum/gulp.git"
}
}

View File

@@ -0,0 +1,82 @@
/*global Pusher*/
import { extend } from 'flarum/extend';
import app from 'flarum/app';
import DiscussionList from 'flarum/components/DiscussionList';
import DiscussionPage from 'flarum/components/DiscussionPage';
import IndexPage from 'flarum/components/IndexPage';
app.initializers.add('pusher', () => {
const loadPusher = m.deferred();
$.getScript('//js.pusher.com/3.0/pusher.min.js', () => {
loadPusher.resolve(new Pusher(app.forum.attribute('pusherKey')).subscribe('public'));
});
app.pusher = loadPusher.promise;
app.pushedUpdates = [];
extend(DiscussionList.prototype, 'config', function(x, isInitialized, context) {
if (isInitialized) return;
app.pusher.then(channel => {
channel.bind('newPost', data => {
const params = this.props.params;
if (!params.q && !params.sort) {
if (params.tags) {
const tag = app.store.getBy('tags', 'slug', params.tags);
if (data.tagIds.indexOf(tag.id()) === -1) return;
}
if ((!app.current.discussion || data.discussionId !== app.current.discussion.id()) && app.pushedUpdates.indexOf(data.discussionId) === -1) {
app.pushedUpdates.push(data.discussionId);
m.redraw();
}
}
});
context.onunload = () => channel.unbind();
});
});
extend(DiscussionList.prototype, 'view', function(vdom) {
if (app.pushedUpdates) {
const count = app.pushedUpdates.length;
if (count) {
vdom.children.unshift(
<button className="Button Button--block DiscussionList-update"
onclick={() => {
app.pushedUpdates = [];
this.refresh();
}}
config={(element, isInitialized) => {
if (!isInitialized) $(element).hide().fadeIn();
}}>
{app.trans('pusher.show_updated_discussions', {count})}
</button>
);
}
}
});
extend(DiscussionPage.prototype, 'config', function(x, isInitialized, context) {
if (isInitialized) return;
app.pusher.then(channel => {
channel.bind('newPost', data => {
if (this.discussion && this.discussion.id() === data.discussionId && this.stream) {
app.store.find('discussions', this.discussion.id()).then(() => this.stream.update());
}
});
context.onunload = () => channel.unbind();
});
});
extend(IndexPage.prototype, 'actionItems', items => {
delete items.refresh;
});
});