Node.js based forum software built for the modern web
removed app.loadConfig
barisusakli04084807c2a5
diff --git a/public/src/app.js b/public/src/app.jsindex ab8da090df..64ebe9b84c 100644--- a/public/src/app.js+++ b/public/src/app.js@@ -1,8 +1,7 @@"use strict";-/*global io, templates, translator, ajaxify, utils, bootbox, RELATIVE_PATH*/+/*global io, templates, translator, ajaxify, utils, bootbox, RELATIVE_PATH, config*/-var socket,- config,+var socket,app = {'username': null,'uid': null,@@ -17,6 +16,74 @@ var socket,var showWelcomeMessage = false;var reconnecting = false;+ function socketIOConnect() {+ var ioParams = {+ reconnectionAttempts: config.maxReconnectionAttempts,+ reconnectionDelay : config.reconnectionDelay,+ transports: config.socketioTransports,+ path: config.relative_path + '/socket.io'+ };++ socket = io.connect(config.websocketAddress, ioParams);+ reconnecting = false;++ socket.on('event:connect', function (data) {+ // TODO : deprecate in 0.7.0, use app.user+ app.username = data.username;+ app.userslug = data.userslug;+ app.picture = data.picture;+ app.uid = data.uid;+ app.isAdmin = data.isAdmin;++ app.user = data;++ app.showLoginMessage();+ app.replaceSelfLinks();+ $(window).trigger('action:connected');+ app.isConnected = true;+ });++ socket.on('connect', onSocketConnect);++ socket.on('event:disconnect', function() {+ $(window).trigger('action:disconnected');+ app.isConnected = false;+ socket.socket.connect();+ });++ socket.on('reconnecting', function (data, attempt) {+ if(attempt === parseInt(config.maxReconnectionAttempts, 10)) {+ socket.socket.reconnectionAttempts = 0;+ socket.socket.reconnectionDelay = config.reconnectionDelay;+ return;+ }++ reconnecting = true;+ var reconnectEl = $('#reconnect');++ if (!reconnectEl.hasClass('active')) {+ reconnectEl.html('<i class="fa fa-spinner fa-spin"></i>');+ }++ reconnectEl.addClass('active').removeClass("hide").tooltip({+ placement: 'bottom'+ });+ });++ socket.on('event:banned', function() {+ app.alert({+ title: '[[global:alert.banned]]',+ message: '[[global:alert.banned.message]]',+ type: 'danger',+ timeout: 1000+ });++ setTimeout(function() {+ window.location.href = config.relative_path + '/';+ }, 1000);+ });+ }+function onSocketConnect(data) {if (reconnecting) {var reconnectEl = $('#reconnect');@@ -64,109 +131,6 @@ var socket,}}- function onConfigLoad(data) {- config = data;-- exposeConfigToTemplates();-- if(socket) {- socket.disconnect();- setTimeout(function() {- socket.connect();- }, 200);- } else {- var ioParams = {- reconnectionAttempts: config.maxReconnectionAttempts,- reconnectionDelay : config.reconnectionDelay,- transports: config.socketioTransports,- path: RELATIVE_PATH + '/socket.io'- };-- socket = io.connect(config.websocketAddress, ioParams);- reconnecting = false;-- socket.on('event:connect', function (data) {- // TODO : deprecate in 0.7.0, use app.user- app.username = data.username;- app.userslug = data.userslug;- app.picture = data.picture;- app.uid = data.uid;- app.isAdmin = data.isAdmin;-- app.user = data;-- templates.setGlobal('loggedIn', parseInt(data.uid, 10) !== 0);-- app.showLoginMessage();- app.replaceSelfLinks();- $(window).trigger('action:connected');- app.isConnected = true;- });-- socket.on('event:alert', function (data) {- app.alert(data);- });-- socket.on('connect', onSocketConnect);-- socket.on('event:disconnect', function() {- $(window).trigger('action:disconnected');- app.isConnected = false;- socket.socket.connect();- });-- socket.on('reconnecting', function (data, attempt) {- if(attempt === parseInt(config.maxReconnectionAttempts, 10)) {- socket.socket.reconnectionAttempts = 0;- socket.socket.reconnectionDelay = config.reconnectionDelay;- return;- }-- reconnecting = true;- var reconnectEl = $('#reconnect');-- if (!reconnectEl.hasClass('active')) {- reconnectEl.html('<i class="fa fa-spinner fa-spin"></i>');- }-- reconnectEl.addClass('active').removeClass("hide").tooltip({- placement: 'bottom'- });- });-- socket.on('event:banned', function() {- app.alert({- title: '[[global:alert.banned]]',- message: '[[global:alert.banned.message]]',- type: 'danger',- timeout: 1000- });-- setTimeout(function() {- window.location.href = RELATIVE_PATH + '/';- }, 1000);- });-- app.cacheBuster = config['cache-buster'];-- require(['csrf'], function(csrf) {- csrf.set(data.csrf_token);- });-- bootbox.setDefaults({- locale: config.userLang- });- }- }-- app.loadConfig = function() {- $.ajax({- url: RELATIVE_PATH + '/api/config',- success: onConfigLoad,- async: false- });- };-app.logout = function() {require(['csrf'], function(csrf) {$.ajax(RELATIVE_PATH + '/logout', {@@ -402,6 +366,7 @@ var socket,function exposeConfigToTemplates() {$(document).ready(function() {+ templates.setGlobal('loggedIn', config.loggedIn);templates.setGlobal('relative_path', RELATIVE_PATH);for(var key in config) {if (config.hasOwnProperty(key)) {@@ -609,7 +574,20 @@ var socket,showWelcomeMessage = window.location.href.indexOf('loggedin') !== -1;- app.loadConfig();+ exposeConfigToTemplates();++ socketIOConnect();++ app.cacheBuster = config['cache-buster'];++ require(['csrf'], function(csrf) {+ csrf.set(config.csrf_token);+ });++ bootbox.setDefaults({+ locale: config.userLang+ });+app.alternatingTitle('');}());diff --git a/public/src/client/account/settings.js b/public/src/client/account/settings.jsindex 107e766c77..3dde90dd98 100644--- a/public/src/client/account/settings.js+++ b/public/src/client/account/settings.js@@ -1,3 +1,7 @@+'use strict';++/*global define, socket, app, ajaxify, config*/+define('forum/account/settings', ['forum/account/header'], function(header) {var AccountSettings = {};@@ -26,13 +30,19 @@ define('forum/account/settings', ['forum/account/header'], function(header) {}});- socket.emit('user.saveSettings', {uid: ajaxify.variables.get('theirid'), settings: settings}, function(err) {+ socket.emit('user.saveSettings', {uid: ajaxify.variables.get('theirid'), settings: settings}, function(err, newSettings) {if (err) {return app.alertError(err.message);}app.alertSuccess('[[success:settings-saved]]');- app.loadConfig();++ for (var key in newSettings) {+ if (newSettings.hasOwnProperty(key)) {+ config[key] = newSettings[key];+ }+ }+if (parseInt(app.uid, 10) === parseInt(ajaxify.variables.get('theirid'), 10)) {ajaxify.refresh();}diff --git a/src/middleware/middleware.js b/src/middleware/middleware.jsindex c09a24fc4b..25691d0e42 100644--- a/src/middleware/middleware.js+++ b/src/middleware/middleware.js@@ -216,6 +216,10 @@ middleware.renderHeader = function(req, res, callback) {};plugins.fireHook('filter:header.build', custom_header, function(err, custom_header) {+ if (err) {+ return next(err);+ }+var defaultMetaTags = [{name: 'viewport',content: 'width=device-width, initial-scale=1.0, user-scalable=no'@@ -260,6 +264,8 @@ middleware.renderHeader = function(req, res, callback) {}}+ templateValues.config = JSON.stringify(res.locals.config);+templateValues.metaTags = defaultMetaTags.concat(res.locals.metaTags || []).map(function(tag) {if(!tag || typeof tag.content !== 'string') {winston.warn('Invalid meta tag. ', tag);diff --git a/src/user/settings.js b/src/user/settings.jsindex 0e857833db..3bda78c315 100644--- a/src/user/settings.js+++ b/src/user/settings.js@@ -1,7 +1,8 @@'use strict';-var meta = require('../meta'),+var async = require('async'),+ meta = require('../meta'),db = require('../database'),plugins = require('../plugins');@@ -82,22 +83,30 @@ module.exports = function(User) {data.language = data.language || meta.config.defaultLang;plugins.fireHook('action:user.saveSettings', {uid: uid, settings: data});- db.setObject('user:' + uid + ':settings', {- showemail: data.showemail,- showfullname: data.showfullname,- openOutgoingLinksInNewTab: data.openOutgoingLinksInNewTab,- dailyDigestFreq: data.dailyDigestFreq || 'off',- usePagination: data.usePagination,- topicsPerPage: Math.min(data.topicsPerPage, 20),- postsPerPage: Math.min(data.postsPerPage, 20),- notificationSounds: data.notificationSounds,- language: data.language || meta.config.defaultLang,- followTopicsOnCreate: data.followTopicsOnCreate,- followTopicsOnReply: data.followTopicsOnReply,- sendChatNotifications: data.sendChatNotifications,- restrictChat: data.restrictChat,- topicSearchEnabled: data.topicSearchEnabled- }, callback);++ async.waterfall([+ function(next) {+ db.setObject('user:' + uid + ':settings', {+ showemail: data.showemail,+ showfullname: data.showfullname,+ openOutgoingLinksInNewTab: data.openOutgoingLinksInNewTab,+ dailyDigestFreq: data.dailyDigestFreq || 'off',+ usePagination: data.usePagination,+ topicsPerPage: Math.min(data.topicsPerPage, 20),+ postsPerPage: Math.min(data.postsPerPage, 20),+ notificationSounds: data.notificationSounds,+ language: data.language || meta.config.defaultLang,+ followTopicsOnCreate: data.followTopicsOnCreate,+ followTopicsOnReply: data.followTopicsOnReply,+ sendChatNotifications: data.sendChatNotifications,+ restrictChat: data.restrictChat,+ topicSearchEnabled: data.topicSearchEnabled+ }, next);+ },+ function(next) {+ User.getSettings(uid, next);+ }+ ], callback);};User.setSetting = function(uid, key, value, callback) {