mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-06 15:42:52 +01:00
Merge pull request #5456 from NodeBB/sounds-refactor
Sound system improvements
This commit is contained in:
@@ -37,11 +37,8 @@ settingsController.get = function (req, res, callback) {
|
||||
homePageRoutes: function (next) {
|
||||
getHomePageRoutes(next);
|
||||
},
|
||||
sounds: function (next) {
|
||||
meta.sounds.getFiles(next);
|
||||
},
|
||||
soundsMapping: function (next) {
|
||||
meta.sounds.getMapping(userData.uid, next);
|
||||
meta.sounds.getUserSoundMap(userData.uid, next);
|
||||
}
|
||||
}, next);
|
||||
},
|
||||
@@ -50,19 +47,47 @@ settingsController.get = function (req, res, callback) {
|
||||
userData.languages = results.languages;
|
||||
userData.homePageRoutes = results.homePageRoutes;
|
||||
|
||||
var soundSettings = {
|
||||
'notificationSound': 'notification',
|
||||
'incomingChatSound': 'chat-incoming',
|
||||
'outgoingChatSound': 'chat-outgoing'
|
||||
var types = [
|
||||
'notification',
|
||||
'chat-incoming',
|
||||
'chat-outgoing',
|
||||
];
|
||||
var aliases = {
|
||||
'notification': 'notificationSound',
|
||||
'chat-incoming': 'incomingChatSound',
|
||||
'chat-outgoing': 'outgoingChatSound',
|
||||
};
|
||||
|
||||
Object.keys(soundSettings).forEach(function (setting) {
|
||||
userData[setting] = Object.keys(results.sounds).map(function (name) {
|
||||
return {name: name, selected: name === results.soundsMapping[soundSettings[setting]]};
|
||||
types.forEach(function (type) {
|
||||
var soundpacks = plugins.soundpacks.map(function (pack) {
|
||||
var sounds = Object.keys(pack.sounds).map(function (soundName) {
|
||||
var value = pack.name + ' | ' + soundName;
|
||||
return {
|
||||
name: soundName,
|
||||
value: value,
|
||||
selected: value === results.soundsMapping[type],
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
name: pack.name,
|
||||
sounds: sounds,
|
||||
};
|
||||
});
|
||||
|
||||
userData[type + '-sound'] = soundpacks;
|
||||
// fallback
|
||||
userData[aliases[type]] = soundpacks.concat.apply([], soundpacks.map(function (pack) {
|
||||
return pack.sounds.map(function (sound) {
|
||||
return {
|
||||
name: sound.value,
|
||||
selected: sound.selected,
|
||||
};
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
plugins.fireHook('filter:user.customSettings', {settings: results.settings, customSettings: [], uid: req.uid}, next);
|
||||
plugins.fireHook('filter:user.customSettings', { settings: results.settings, customSettings: [], uid: req.uid }, next);
|
||||
},
|
||||
function (data, next) {
|
||||
userData.customSettings = data.customSettings;
|
||||
@@ -75,10 +100,10 @@ settingsController.get = function (req, res, callback) {
|
||||
}
|
||||
|
||||
userData.dailyDigestFreqOptions = [
|
||||
{value: 'off', name: '[[user:digest_off]]', selected: 'off' === userData.settings.dailyDigestFreq},
|
||||
{value: 'day', name: '[[user:digest_daily]]', selected: 'day' === userData.settings.dailyDigestFreq},
|
||||
{value: 'week', name: '[[user:digest_weekly]]', selected: 'week' === userData.settings.dailyDigestFreq},
|
||||
{value: 'month', name: '[[user:digest_monthly]]', selected: 'month' === userData.settings.dailyDigestFreq}
|
||||
{ value: 'off', name: '[[user:digest_off]]', selected: 'off' === userData.settings.dailyDigestFreq },
|
||||
{ value: 'day', name: '[[user:digest_daily]]', selected: 'day' === userData.settings.dailyDigestFreq },
|
||||
{ value: 'week', name: '[[user:digest_weekly]]', selected: 'week' === userData.settings.dailyDigestFreq },
|
||||
{ value: 'month', name: '[[user:digest_monthly]]', selected: 'month' === userData.settings.dailyDigestFreq }
|
||||
];
|
||||
|
||||
|
||||
|
||||
@@ -1,24 +1,46 @@
|
||||
'use strict';
|
||||
|
||||
var meta = require('../../meta');
|
||||
var plugins = require('../../plugins');
|
||||
var db = require('../../database');
|
||||
|
||||
var soundsController = {};
|
||||
|
||||
soundsController.get = function (req, res, next) {
|
||||
meta.sounds.getFiles(function (err, sounds) {
|
||||
db.getObject('settings:sounds', function (err, settings) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
settings = settings || {};
|
||||
|
||||
sounds = Object.keys(sounds).map(function (name) {
|
||||
return {
|
||||
name: name
|
||||
};
|
||||
var types = [
|
||||
'notification',
|
||||
'chat-incoming',
|
||||
'chat-outgoing',
|
||||
];
|
||||
var output = {};
|
||||
|
||||
types.forEach(function (type) {
|
||||
var soundpacks = plugins.soundpacks.map(function (pack) {
|
||||
var sounds = Object.keys(pack.sounds).map(function (soundName) {
|
||||
var value = pack.name + ' | ' + soundName;
|
||||
return {
|
||||
name: soundName,
|
||||
value: value,
|
||||
selected: value === settings[type],
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
name: pack.name,
|
||||
sounds: sounds,
|
||||
};
|
||||
});
|
||||
|
||||
output[type + '-sound'] = soundpacks;
|
||||
});
|
||||
|
||||
res.render('admin/general/sounds', {
|
||||
sounds: sounds
|
||||
});
|
||||
res.render('admin/general/sounds', output);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ var path = require('path');
|
||||
var async = require('async');
|
||||
var nconf = require('nconf');
|
||||
var winston = require('winston');
|
||||
|
||||
var meta = require('../../meta');
|
||||
var file = require('../../file');
|
||||
var image = require('../../image');
|
||||
var plugins = require('../../plugins');
|
||||
@@ -105,12 +107,7 @@ uploadsController.uploadSound = function (req, res, next) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
var soundsPath = path.join(__dirname, '../../../build/public/sounds'),
|
||||
filePath = path.join(nconf.get('upload_path'), 'sounds', uploadedFile.name);
|
||||
|
||||
file.link(filePath, path.join(soundsPath, path.basename(filePath)));
|
||||
|
||||
fs.unlink(uploadedFile.path, function (err) {
|
||||
meta.sounds.build(function (err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user