This repository has been archived by the owner on Jan 15, 2020. It is now read-only.
forked from NodeBB-Community/nodebb-plugin-shoutbox
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlibrary.js
127 lines (101 loc) · 3.22 KB
/
library.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
"use strict";
var NodeBB = require('./lib/nodebb'),
Config = require('./lib/config'),
Sockets = require('./lib/sockets'),
Commands = require('./lib/commands'),
app,
Shoutbox = {};
Shoutbox.init = {};
Shoutbox.widget = {};
Shoutbox.settings = {};
Shoutbox.init.load = function(params, callback) {
function renderGlobal(req, res, next) {
Config.getTemplateData(function(data) {
res.render(Config.plugin.id, data);
});
}
function renderAdmin(req, res, next) {
Config.getTemplateData(function(data) {
res.render('admin/plugins/' + Config.plugin.id, data);
});
}
function renderChatRoom( req, res, next) {
Config.getTemplateData(function(data) {
data.room = req.params.room;
res.render(Config.plugin.id, data)
});
}
var router = params.router;
router.get('/' + Config.plugin.id, params.middleware.buildHeader, renderGlobal);
router.get('/api/' + Config.plugin.id, renderGlobal);
router.get('/chat/:room', params.middleware.buildHeader, renderChatRoom);
router.get('/api/chat/:room', params.middleware.buildHeader, renderChatRoom);
router.get('/admin/plugins/' + Config.plugin.id, params.middleware.admin.buildHeader, renderAdmin);
router.get('/api/admin/plugins/' + Config.plugin.id, renderAdmin);
NodeBB.SocketPlugins[Config.plugin.id] = Sockets.events;
NodeBB.SocketAdmin[Config.plugin.id] = Config.adminSockets;
app = params.app;
Config.init(callback);
};
Shoutbox.init.addGlobalNavigation = function(header, callback) {
if (Config.global.get('toggles.headerLink')) {
header.navigation.push({
class: '',
iconClass: 'fa fa-fw ' + Config.plugin.icon,
route: '/' + Config.plugin.id,
text: Config.plugin.name
});
}
callback(null, header);
};
Shoutbox.init.addAdminNavigation = function(header, callback) {
header.plugins.push({
route: '/plugins/' + Config.plugin.id,
icon: Config.plugin.icon,
name: Config.plugin.name
});
callback(null, header);
};
Shoutbox.init.getSounds = function(sounds, callback) {
sounds.push(__dirname + '/public/sounds/shoutbox-notification.mp3');
sounds.push(__dirname + '/public/sounds/shoutbox-wobblysausage.mp3');
callback(null, sounds);
};
Shoutbox.widget.define = function(widgets, callback) {
widgets.push({
name: Config.plugin.name,
widget: Config.plugin.id,
description: Config.plugin.description,
content: ''
});
callback(null, widgets);
};
Shoutbox.widget.render = function(widget, callback) {
//Remove any container
widget.data.container = '';
Config.user.get({ uid: widget.uid, settings: {} }, function(err, result) {
Config.getTemplateData(function(data) {
data.hiddenStyle = '';
if (!err && result && result.settings && parseInt(result.settings['shoutbox:toggles:hide'], 10) == 1) {
data.hiddenStyle = 'display: none;';
}
app.render('shoutbox/panel', data, callback);
});
});
};
Shoutbox.settings.addUserSettings = function(settings, callback) {
app.render('shoutbox/user/settings', function(err, html) {
settings.push({
title: Config.plugin.name,
content: html
});
callback(null, settings);
});
};
Shoutbox.settings.getUserSettings = function(data, callback) {
Config.user.get(data, callback);
};
Shoutbox.settings.saveUserSettings = function(data) {
Config.user.save(data);
};
module.exports = Shoutbox;