-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathindex.js
More file actions
63 lines (51 loc) · 1.68 KB
/
Copy pathindex.js
File metadata and controls
63 lines (51 loc) · 1.68 KB
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
'use strict';
const user = nodebb.require('./src/user');
const plugin = module.exports;
let app;
plugin.init = async (hookData) => {
app = hookData.app;
return hookData;
};
plugin.filterConfigGet = async (config) => {
const userSettings = await user.getSettings(config.uid);
config.notificationSound = userSettings.notificationSound || '';
config.incomingChatSound = userSettings.incomingChatSound || '';
config.outgoingChatSound = userSettings.outgoingChatSound || '';
return config;
};
plugin.filterUserSaveSettings = async (hookData) => {
if (hookData.data) {
hookData.settings.notificationSound = hookData.data.notificationSound || '';
hookData.settings.incomingChatSound = hookData.data.incomingChatSound || '';
hookData.settings.outgoingChatSound = hookData.data.outgoingChatSound || '';
}
return hookData;
};
plugin.filterUserCustomSettings = async (hookData) => {
const userSettings = await user.getSettings(hookData.uid);
const soundsMap = {
'Deedle-dum': 'notification.mp3',
'Water drop (high)': 'waterdrop-high.mp3',
'Water drop (low)': 'waterdrop-low.mp3',
};
function getOptions(type) {
return Object.keys(soundsMap).map(function (name) {
return {
name: name,
value: soundsMap[name],
selected: String(userSettings[type]) === String(soundsMap[name]),
};
});
}
const tplData = {
notificationSound: getOptions('notificationSound'),
incomingChatSound: getOptions('incomingChatSound'),
outgoingChatSound: getOptions('outgoingChatSound')
};
const settingsHtml = await app.renderAsync('partials/account/settings/sounds', tplData);
hookData.customSettings.push({
title: '[[sounds:sounds]]',
content: settingsHtml,
});
return hookData;
};