mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
closes #2166
This commit is contained in:
@@ -121,5 +121,6 @@
|
||||
"allowed-file-types": "Allowed file types are %1",
|
||||
|
||||
"unsaved-changes": "You have unsaved changes. Are you sure you wish to navigate away?",
|
||||
"reconnecting-message": "Looks like your connection to %1 was lost, please wait while we try to reconnect."
|
||||
"reconnecting-message": "Looks like your connection to %1 was lost, please wait while we try to reconnect.",
|
||||
"play": "Play"
|
||||
}
|
||||
|
||||
@@ -98,6 +98,10 @@
|
||||
"posts_per_page": "Posts per Page",
|
||||
|
||||
"notification_sounds" : "Play a sound when you receive a notification",
|
||||
"notifications_and_sounds": "Notifications & Sounds",
|
||||
"incoming-message-sound": "Incoming message sound",
|
||||
"outgoing-message-sound": "Outgoing message sound",
|
||||
"notification-sound": "Notification sound",
|
||||
|
||||
"browsing": "Browsing Settings",
|
||||
"open_links_in_new_tab": "Open outgoing links in new tab",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
/*global define, socket, app, ajaxify, config*/
|
||||
|
||||
define('forum/account/settings', ['forum/account/header', 'components'], function(header, components) {
|
||||
define('forum/account/settings', ['forum/account/header', 'components', 'sounds'], function(header, components, sounds) {
|
||||
var AccountSettings = {};
|
||||
|
||||
AccountSettings.init = function() {
|
||||
@@ -33,6 +33,13 @@ define('forum/account/settings', ['forum/account/header', 'components'], functio
|
||||
|
||||
$('[data-property="homePageRoute"]').on('change', toggleCustomRoute);
|
||||
|
||||
$('.account').find('button[data-action="play"]').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var fileName = $(this).parent().parent().find('select').val();
|
||||
sounds.playFile(fileName);
|
||||
});
|
||||
|
||||
toggleCustomRoute();
|
||||
|
||||
components.get('user/sessions').find('.timeago').timeago();
|
||||
@@ -77,9 +84,13 @@ define('forum/account/settings', ['forum/account/header', 'components'], functio
|
||||
if (key === 'userLang' && config.userLang !== newSettings.userLang) {
|
||||
requireReload = true;
|
||||
}
|
||||
if (config.hasOwnProperty(key)) {
|
||||
config[key] = newSettings[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sounds.reloadMapping();
|
||||
|
||||
if (requireReload && parseInt(app.user.uid, 10) === parseInt(ajaxify.data.theirid, 10)) {
|
||||
app.alert({
|
||||
|
||||
@@ -9,13 +9,17 @@ define('sounds', ['buzz'], function(buzz) {
|
||||
var files;
|
||||
|
||||
socket.on('event:sounds.reloadMapping', function() {
|
||||
Sounds.reloadMapping();
|
||||
});
|
||||
|
||||
Sounds.reloadMapping = function() {
|
||||
socket.emit('modules.sounds.getMapping', function(err, mapping) {
|
||||
if (err) {
|
||||
return app.alertError('[sounds] Could not load sound mapping!');
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
eventSoundMapping = mapping;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function loadData(callback) {
|
||||
socket.emit('modules.sounds.getData', function(err, data) {
|
||||
@@ -55,10 +59,6 @@ define('sounds', ['buzz'], function(buzz) {
|
||||
Sounds.playFile(eventSoundMapping[name]);
|
||||
}
|
||||
|
||||
if (!config.notificationSounds) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!eventSoundMapping) {
|
||||
return loadData(play);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
var async = require('async');
|
||||
|
||||
var user = require('../../user');
|
||||
var groups = require('../../groups');
|
||||
var languages = require('../../languages');
|
||||
var meta = require('../../meta');
|
||||
var plugins = require('../../plugins');
|
||||
@@ -37,6 +36,9 @@ settingsController.get = function(req, res, callback) {
|
||||
},
|
||||
homePageRoutes: function(next) {
|
||||
getHomePageRoutes(next);
|
||||
},
|
||||
sounds: function(next) {
|
||||
meta.sounds.getFiles(next);
|
||||
}
|
||||
}, next);
|
||||
},
|
||||
@@ -44,6 +46,14 @@ settingsController.get = function(req, res, callback) {
|
||||
userData.settings = results.settings;
|
||||
userData.languages = results.languages;
|
||||
userData.homePageRoutes = results.homePageRoutes;
|
||||
|
||||
var soundSettings = ['notificationSound', 'incomingChatSound', 'outgoingChatSound'];
|
||||
soundSettings.forEach(function(setting) {
|
||||
userData[setting] = Object.keys(results.sounds).map(function(name) {
|
||||
return {name: name, selected: name === userData.settings[setting]};
|
||||
});
|
||||
});
|
||||
|
||||
plugins.fireHook('filter:user.customSettings', {settings: results.settings, customSettings: [], uid: req.uid}, next);
|
||||
},
|
||||
function(data, next) {
|
||||
|
||||
@@ -12,7 +12,6 @@ var categories = require('../categories');
|
||||
var privileges = require('../privileges');
|
||||
var plugins = require('../plugins');
|
||||
var widgets = require('../widgets');
|
||||
var helpers = require('../controllers/helpers');
|
||||
var accountHelpers = require('../controllers/accounts/helpers');
|
||||
|
||||
var apiController = {};
|
||||
@@ -68,14 +67,12 @@ apiController.getConfig = function(req, res, next) {
|
||||
if (!req.user) {
|
||||
return next(null, config);
|
||||
}
|
||||
user.getSettings(req.uid, function(err, settings) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
user.getSettings(req.uid, next);
|
||||
},
|
||||
function (settings, next) {
|
||||
config.usePagination = settings.usePagination;
|
||||
config.topicsPerPage = settings.topicsPerPage;
|
||||
config.postsPerPage = settings.postsPerPage;
|
||||
config.notificationSounds = settings.notificationSounds;
|
||||
config.userLang = (req.query.lang ? validator.escape(String(req.query.lang)) : null) || settings.userLang || config.defaultLang;
|
||||
config.openOutgoingLinksInNewTab = settings.openOutgoingLinksInNewTab;
|
||||
config.topicPostSort = settings.topicPostSort || config.topicPostSort;
|
||||
@@ -83,10 +80,6 @@ apiController.getConfig = function(req, res, next) {
|
||||
config.topicSearchEnabled = settings.topicSearchEnabled || false;
|
||||
config.delayImageLoading = settings.delayImageLoading !== undefined ? settings.delayImageLoading : true;
|
||||
config.bootswatchSkin = settings.bootswatchSkin || config.bootswatchSkin;
|
||||
next(null, config);
|
||||
});
|
||||
},
|
||||
function (config, next) {
|
||||
plugins.fireHook('filter:config.get', config, next);
|
||||
}
|
||||
], function(err, config) {
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
var path = require('path'),
|
||||
fs = require('fs'),
|
||||
nconf = require('nconf'),
|
||||
winston = require('winston'),
|
||||
rimraf = require('rimraf'),
|
||||
mkdirp = require('mkdirp'),
|
||||
async = require('async'),
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var nconf = require('nconf');
|
||||
var winston = require('winston');
|
||||
var rimraf = require('rimraf');
|
||||
var mkdirp = require('mkdirp');
|
||||
var async = require('async');
|
||||
|
||||
plugins = require('../plugins'),
|
||||
db = require('../database');
|
||||
var user = require('../user');
|
||||
var plugins = require('../plugins');
|
||||
var db = require('../database');
|
||||
|
||||
module.exports = function(Meta) {
|
||||
|
||||
@@ -58,20 +59,31 @@ module.exports = function(Meta) {
|
||||
});
|
||||
};
|
||||
|
||||
Meta.sounds.getMapping = function(callback) {
|
||||
db.getObject('settings:sounds', function(err, sounds) {
|
||||
if (err || !sounds) {
|
||||
// Send default sounds
|
||||
var defaults = {
|
||||
'notification': 'notification.mp3',
|
||||
'chat-incoming': 'waterdrop-high.mp3',
|
||||
'chat-outgoing': undefined
|
||||
};
|
||||
|
||||
return callback(null, defaults);
|
||||
Meta.sounds.getMapping = function(uid, callback) {
|
||||
async.parallel({
|
||||
defaultMapping: function(next) {
|
||||
db.getObject('settings:sounds', next);
|
||||
},
|
||||
userSettings: function(next) {
|
||||
user.getSettings(uid, next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
var userSettings = results.userSettings;
|
||||
var defaultMapping = results.defaultMapping || {};
|
||||
var soundMapping = {};
|
||||
soundMapping.notification = (userSettings.notificationSound || userSettings.notificationSound === '') ?
|
||||
userSettings.notificationSound : defaultMapping.notification || 'notification.mp3';
|
||||
|
||||
callback(null, sounds);
|
||||
soundMapping['chat-incoming'] = (userSettings.incomingChatSound || userSettings.incomingChatSound === '') ?
|
||||
userSettings.incomingChatSound : defaultMapping['chat-incoming'] || 'waterdrop-high.mp3';
|
||||
|
||||
soundMapping['chat-outgoing'] = (userSettings.outgoingChatSound || userSettings.outgoingChatSound === '') ?
|
||||
userSettings.outgoingChatSound : defaultMapping['chat-outgoing'] || undefined;
|
||||
|
||||
callback(null, soundMapping);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -313,12 +313,12 @@ SocketModules.sounds.getSounds = function(socket, data, callback) {
|
||||
};
|
||||
|
||||
SocketModules.sounds.getMapping = function(socket, data, callback) {
|
||||
meta.sounds.getMapping(callback);
|
||||
meta.sounds.getMapping(socket.uid, callback);
|
||||
};
|
||||
|
||||
SocketModules.sounds.getData = function(socket, data, callback) {
|
||||
async.parallel({
|
||||
mapping: async.apply(meta.sounds.getMapping),
|
||||
mapping: async.apply(meta.sounds.getMapping, socket.uid),
|
||||
files: async.apply(meta.sounds.getFiles)
|
||||
}, callback);
|
||||
};
|
||||
|
||||
@@ -65,7 +65,6 @@ module.exports = function(User) {
|
||||
settings.usePagination = parseInt(getSetting(settings, 'usePagination', 0), 10) === 1;
|
||||
settings.topicsPerPage = Math.min(settings.topicsPerPage ? parseInt(settings.topicsPerPage, 10) : defaultTopicsPerPage, defaultTopicsPerPage);
|
||||
settings.postsPerPage = Math.min(settings.postsPerPage ? parseInt(settings.postsPerPage, 10) : defaultPostsPerPage, defaultPostsPerPage);
|
||||
settings.notificationSounds = parseInt(getSetting(settings, 'notificationSounds', 0), 10) === 1;
|
||||
settings.userLang = settings.userLang || meta.config.defaultLang || 'en_GB';
|
||||
settings.topicPostSort = getSetting(settings, 'topicPostSort', 'oldest_to_newest');
|
||||
settings.categoryTopicSort = getSetting(settings, 'categoryTopicSort', 'newest_to_oldest');
|
||||
@@ -113,7 +112,6 @@ module.exports = function(User) {
|
||||
usePagination: data.usePagination,
|
||||
topicsPerPage: Math.min(data.topicsPerPage, parseInt(meta.config.topicsPerPage, 10) || 20),
|
||||
postsPerPage: Math.min(data.postsPerPage, parseInt(meta.config.postsPerPage, 10) || 20),
|
||||
notificationSounds: data.notificationSounds,
|
||||
userLang: data.userLang || meta.config.defaultLang,
|
||||
followTopicsOnCreate: data.followTopicsOnCreate,
|
||||
followTopicsOnReply: data.followTopicsOnReply,
|
||||
@@ -123,7 +121,10 @@ module.exports = function(User) {
|
||||
topicSearchEnabled: data.topicSearchEnabled,
|
||||
delayImageLoading: data.delayImageLoading,
|
||||
homePageRoute : ((data.homePageRoute === 'custom' ? data.homePageCustom : data.homePageRoute) || '').replace(/^\//, ''),
|
||||
scrollToMyPost: data.scrollToMyPost
|
||||
scrollToMyPost: data.scrollToMyPost,
|
||||
notificationSound: data.notificationSound,
|
||||
incomingChatSound: data.incomingChatSound,
|
||||
outgoingChatSound: data.outgoingChatSound
|
||||
};
|
||||
|
||||
if (data.bootswatchSkin) {
|
||||
|
||||
@@ -261,13 +261,6 @@
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="checkbox">
|
||||
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect">
|
||||
<input class="mdl-switch__input" type="checkbox" data-field="notificationSounds" />
|
||||
<span class="mdl-switch__label">Play a sound when you receive a notification</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user