Node.js based forum software built for the modern web
closes #2166
barisusakli6d34bb465755
diff --git a/public/language/en_GB/global.json b/public/language/en_GB/global.jsonindex 66ea4af420..e2785de2f5 100644--- a/public/language/en_GB/global.json+++ b/public/language/en_GB/global.json@@ -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"}diff --git a/public/language/en_GB/user.json b/public/language/en_GB/user.jsonindex b1cb065de5..5863d4d67c 100644--- a/public/language/en_GB/user.json+++ b/public/language/en_GB/user.json@@ -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",diff --git a/public/src/client/account/settings.js b/public/src/client/account/settings.jsindex 1060492bf0..cc9aaf0439 100644--- a/public/src/client/account/settings.js+++ b/public/src/client/account/settings.js@@ -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,10 +84,14 @@ define('forum/account/settings', ['forum/account/header', 'components'], functioif (key === 'userLang' && config.userLang !== newSettings.userLang) {requireReload = true;}- config[key] = newSettings[key];+ if (config.hasOwnProperty(key)) {+ config[key] = newSettings[key];+ }}}+ sounds.reloadMapping();+if (requireReload && parseInt(app.user.uid, 10) === parseInt(ajaxify.data.theirid, 10)) {app.alert({id: 'setting-change',diff --git a/public/src/modules/sounds.js b/public/src/modules/sounds.jsindex 052e804f6e..a9a1840fd4 100644--- a/public/src/modules/sounds.js+++ b/public/src/modules/sounds.js@@ -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);}diff --git a/src/controllers/accounts/settings.js b/src/controllers/accounts/settings.jsindex 3b169bf83c..11ea490d6f 100644--- a/src/controllers/accounts/settings.js+++ b/src/controllers/accounts/settings.js@@ -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) {diff --git a/src/controllers/api.js b/src/controllers/api.jsindex 968a0d86a6..42cc74e7e7 100644--- a/src/controllers/api.js+++ b/src/controllers/api.js@@ -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,25 +67,19 @@ 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);- }- 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;- config.categoryTopicSort = settings.categoryTopicSort || config.categoryTopicSort;- config.topicSearchEnabled = settings.topicSearchEnabled || false;- config.delayImageLoading = settings.delayImageLoading !== undefined ? settings.delayImageLoading : true;- config.bootswatchSkin = settings.bootswatchSkin || config.bootswatchSkin;- next(null, config);- });+ user.getSettings(req.uid, next);},- function (config, next) {+ function (settings, next) {+ config.usePagination = settings.usePagination;+ config.topicsPerPage = settings.topicsPerPage;+ config.postsPerPage = settings.postsPerPage;+ 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;+ config.categoryTopicSort = settings.categoryTopicSort || config.categoryTopicSort;+ config.topicSearchEnabled = settings.topicSearchEnabled || false;+ config.delayImageLoading = settings.delayImageLoading !== undefined ? settings.delayImageLoading : true;+ config.bootswatchSkin = settings.bootswatchSkin || config.bootswatchSkin;plugins.fireHook('filter:config.get', config, next);}], function(err, config) {diff --git a/src/meta/sounds.js b/src/meta/sounds.jsindex c802458b14..c413def9e3 100644--- a/src/meta/sounds.js+++ b/src/meta/sounds.js@@ -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'),-- plugins = require('../plugins'),- db = require('../database');+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');++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';++ 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, sounds);+ callback(null, soundMapping);});};diff --git a/src/socket.io/modules.js b/src/socket.io/modules.jsindex 568d971b65..954d407d5f 100644--- a/src/socket.io/modules.js+++ b/src/socket.io/modules.js@@ -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);};diff --git a/src/user/settings.js b/src/user/settings.jsindex 55bf2b14ff..f4d9b37986 100644--- a/src/user/settings.js+++ b/src/user/settings.js@@ -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) {diff --git a/src/views/admin/settings/user.tpl b/src/views/admin/settings/user.tplindex 575a4a07f9..aecdd1a0cb 100644--- a/src/views/admin/settings/user.tpl+++ b/src/views/admin/settings/user.tpl@@ -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>