-
Notifications
You must be signed in to change notification settings - Fork 34
/
library.js
106 lines (82 loc) · 2.73 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
'use strict';
const NodeBB = require('./lib/nodebb');
const Config = require('./lib/config');
const Sockets = require('./lib/sockets');
require('./lib/commands');
let app;
const Shoutbox = module.exports;
Shoutbox.init = {};
Shoutbox.widget = {};
Shoutbox.settings = {};
Shoutbox.init.load = function (params, callback) {
const { router } = params;
const routeHelpers = require.main.require('./src/routes/helpers');
routeHelpers.setupPageRoute(router, `/${Config.plugin.id}`, async (req, res) => {
const data = Config.getTemplateData();
res.render(Config.plugin.id, data);
});
routeHelpers.setupAdminPageRoute(router, `/admin/plugins/${Config.plugin.id}`, async (req, res) => {
const data = Config.getTemplateData();
data.title = Config.plugin.name;
res.render(`admin/plugins/${Config.plugin.id}`, data);
});
NodeBB.SocketPlugins[Config.plugin.id] = Sockets.events;
NodeBB.SocketAdmin[Config.plugin.id] = Config.adminSockets;
app = params.app;
Config.init(callback);
};
Shoutbox.init.filterConfigGet = async (config) => {
config.shoutbox = Config.getTemplateData();
config.shoutbox.settings = await Config.user.load(config.uid);
return config;
};
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.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 = async function (widget) {
if (widget.templateData.template.shoutbox) {
return null;
}
// Remove any container
widget.data.container = '';
const data = Config.getTemplateData();
data.title = widget.data.title || '';
data.features = data.features.filter(f => f && f.enabled);
widget.html = await app.renderAsync('shoutbox/panel', data);
return widget;
};
Shoutbox.settings.addUserSettings = async function (settings) {
const html = await app.renderAsync('shoutbox/user/settings', { settings: settings.settings });
settings.customSettings.push({
title: Config.plugin.name,
content: html,
});
return settings;
};
Shoutbox.settings.addUserFieldWhitelist = function (data, callback) {
data.whitelist.push('shoutbox:toggles:sound');
data.whitelist.push('shoutbox:toggles:notification');
data.whitelist.push('shoutbox:toggles:hide');
data.whitelist.push('shoutbox:muted');
callback(null, data);
};
Shoutbox.settings.filterUserGetSettings = async function (data) {
return await Config.user.get(data);
};
Shoutbox.settings.filterUserSaveSettings = async function (hookData) {
return await Config.user.save(hookData);
};