2015-09-25 13:11:11 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
2016-02-24 09:58:14 +02:00
|
|
|
var async = require('async');
|
2015-09-25 13:11:11 -04:00
|
|
|
|
2016-02-24 09:58:14 +02:00
|
|
|
var user = require('../../user');
|
|
|
|
|
var languages = require('../../languages');
|
|
|
|
|
var meta = require('../../meta');
|
|
|
|
|
var plugins = require('../../plugins');
|
|
|
|
|
var privileges = require('../../privileges');
|
|
|
|
|
var categories = require('../../categories');
|
|
|
|
|
var db = require('../../database');
|
|
|
|
|
var helpers = require('../helpers');
|
|
|
|
|
var accountHelpers = require('./helpers');
|
2015-09-25 13:11:11 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
var settingsController = {};
|
|
|
|
|
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
settingsController.get = function (req, res, callback) {
|
2015-09-25 13:11:11 -04:00
|
|
|
var userData;
|
|
|
|
|
async.waterfall([
|
2016-10-13 11:43:39 +02:00
|
|
|
function (next) {
|
2016-09-14 14:33:39 +03:00
|
|
|
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next);
|
2015-09-25 13:11:11 -04:00
|
|
|
},
|
2016-10-13 11:43:39 +02:00
|
|
|
function (_userData, next) {
|
2015-09-25 13:11:11 -04:00
|
|
|
userData = _userData;
|
|
|
|
|
if (!userData) {
|
|
|
|
|
return callback();
|
|
|
|
|
}
|
|
|
|
|
async.parallel({
|
2016-10-13 11:43:39 +02:00
|
|
|
settings: function (next) {
|
2015-09-25 13:11:11 -04:00
|
|
|
user.getSettings(userData.uid, next);
|
|
|
|
|
},
|
2016-10-13 11:43:39 +02:00
|
|
|
languages: function (next) {
|
2015-09-25 13:11:11 -04:00
|
|
|
languages.list(next);
|
2015-11-04 05:55:02 -05:00
|
|
|
},
|
2016-10-13 11:43:39 +02:00
|
|
|
homePageRoutes: function (next) {
|
2015-12-29 10:46:57 +02:00
|
|
|
getHomePageRoutes(next);
|
2016-08-29 12:43:32 +03:00
|
|
|
},
|
2016-10-13 11:43:39 +02:00
|
|
|
sounds: function (next) {
|
2016-08-29 12:43:32 +03:00
|
|
|
meta.sounds.getFiles(next);
|
2016-09-05 21:47:13 +03:00
|
|
|
},
|
2016-10-13 11:43:39 +02:00
|
|
|
soundsMapping: function (next) {
|
2016-09-05 21:47:13 +03:00
|
|
|
meta.sounds.getMapping(userData.uid, next);
|
2017-02-17 19:31:21 -07:00
|
|
|
},
|
2015-09-25 13:11:11 -04:00
|
|
|
}, next);
|
|
|
|
|
},
|
2016-10-13 11:43:39 +02:00
|
|
|
function (results, next) {
|
2015-09-25 13:11:11 -04:00
|
|
|
userData.settings = results.settings;
|
2016-02-24 09:58:14 +02:00
|
|
|
userData.languages = results.languages;
|
2015-11-04 05:55:02 -05:00
|
|
|
userData.homePageRoutes = results.homePageRoutes;
|
2016-08-29 12:43:32 +03:00
|
|
|
|
2016-09-05 21:47:13 +03:00
|
|
|
var soundSettings = {
|
2017-02-18 01:19:20 -07:00
|
|
|
notificationSound: 'notification',
|
|
|
|
|
incomingChatSound: 'chat-incoming',
|
|
|
|
|
outgoingChatSound: 'chat-outgoing',
|
2016-09-05 21:47:13 +03:00
|
|
|
};
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
Object.keys(soundSettings).forEach(function (setting) {
|
|
|
|
|
userData[setting] = Object.keys(results.sounds).map(function (name) {
|
2017-02-18 12:30:49 -07:00
|
|
|
return { name: name, selected: name === results.soundsMapping[soundSettings[setting]] };
|
2016-08-29 12:43:32 +03:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-02-18 12:30:49 -07:00
|
|
|
plugins.fireHook('filter:user.customSettings', { settings: results.settings, customSettings: [], uid: req.uid }, next);
|
2015-09-25 13:11:11 -04:00
|
|
|
},
|
2016-10-13 11:43:39 +02:00
|
|
|
function (data, next) {
|
2015-09-25 13:11:11 -04:00
|
|
|
userData.customSettings = data.customSettings;
|
|
|
|
|
userData.disableEmailSubscriptions = parseInt(meta.config.disableEmailSubscriptions, 10) === 1;
|
|
|
|
|
next();
|
2017-02-17 19:31:21 -07:00
|
|
|
},
|
2016-10-13 11:43:39 +02:00
|
|
|
], function (err) {
|
2015-09-25 13:11:11 -04:00
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
userData.dailyDigestFreqOptions = [
|
2017-02-18 12:30:49 -07:00
|
|
|
{ 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 },
|
2015-09-25 13:11:11 -04:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
userData.bootswatchSkinOptions = [
|
2017-02-18 01:56:23 -07:00
|
|
|
{ name: 'Default', value: 'default' },
|
|
|
|
|
{ name: 'Cerulean', value: 'cerulean' },
|
|
|
|
|
{ name: 'Cosmo', value: 'cosmo' },
|
|
|
|
|
{ name: 'Cyborg', value: 'cyborg' },
|
|
|
|
|
{ name: 'Darkly', value: 'darkly' },
|
|
|
|
|
{ name: 'Flatly', value: 'flatly' },
|
|
|
|
|
{ name: 'Journal', value: 'journal' },
|
|
|
|
|
{ name: 'Lumen', value: 'lumen' },
|
|
|
|
|
{ name: 'Paper', value: 'paper' },
|
|
|
|
|
{ name: 'Readable', value: 'readable' },
|
|
|
|
|
{ name: 'Sandstone', value: 'sandstone' },
|
|
|
|
|
{ name: 'Simplex', value: 'simplex' },
|
|
|
|
|
{ name: 'Slate', value: 'slate' },
|
|
|
|
|
{ name: 'Spacelab', value: 'spacelab' },
|
|
|
|
|
{ name: 'Superhero', value: 'superhero' },
|
|
|
|
|
{ name: 'United', value: 'united' },
|
|
|
|
|
{ name: 'Yeti', value: 'yeti' },
|
2015-09-25 13:11:11 -04:00
|
|
|
];
|
|
|
|
|
|
2016-04-22 19:48:41 +03:00
|
|
|
var isCustom = true;
|
2016-10-13 11:43:39 +02:00
|
|
|
userData.homePageRoutes.forEach(function (route) {
|
2015-11-07 17:11:35 -05:00
|
|
|
route.selected = route.route === userData.settings.homePageRoute;
|
2016-04-22 19:48:41 +03:00
|
|
|
if (route.selected) {
|
|
|
|
|
isCustom = false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2016-05-17 15:45:42 +03:00
|
|
|
if (isCustom && userData.settings.homePageRoute === 'none') {
|
|
|
|
|
isCustom = false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-22 19:48:41 +03:00
|
|
|
userData.homePageRoutes.push({
|
|
|
|
|
route: 'custom',
|
|
|
|
|
name: 'Custom',
|
2017-02-17 19:31:21 -07:00
|
|
|
selected: isCustom,
|
2015-11-07 17:11:35 -05:00
|
|
|
});
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
userData.bootswatchSkinOptions.forEach(function (skin) {
|
2015-09-25 13:11:11 -04:00
|
|
|
skin.selected = skin.value === userData.settings.bootswatchSkin;
|
|
|
|
|
});
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
userData.languages.forEach(function (language) {
|
2015-09-25 13:11:11 -04:00
|
|
|
language.selected = language.code === userData.settings.userLang;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
userData.disableCustomUserSkins = parseInt(meta.config.disableCustomUserSkins, 10) === 1;
|
|
|
|
|
|
2015-11-04 05:55:02 -05:00
|
|
|
userData.allowUserHomePage = parseInt(meta.config.allowUserHomePage, 10) === 1;
|
2016-05-17 15:45:42 +03:00
|
|
|
|
2016-05-11 17:43:37 -07:00
|
|
|
userData.inTopicSearchAvailable = plugins.hasListeners('filter:topic.search');
|
2015-11-04 05:55:02 -05:00
|
|
|
|
2015-09-25 13:11:11 -04:00
|
|
|
userData.title = '[[pages:account/settings]]';
|
2017-02-18 12:30:49 -07:00
|
|
|
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: '[[user:settings]]' }]);
|
2015-09-25 13:11:11 -04:00
|
|
|
|
|
|
|
|
res.render('account/settings', userData);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2015-12-29 10:46:57 +02:00
|
|
|
function getHomePageRoutes(callback) {
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
db.getSortedSetRange('cid:0:children', 0, -1, next);
|
|
|
|
|
},
|
|
|
|
|
function (cids, next) {
|
|
|
|
|
privileges.categories.filterCids('find', cids, 0, next);
|
|
|
|
|
},
|
|
|
|
|
function (cids, next) {
|
|
|
|
|
categories.getCategoriesFields(cids, ['name', 'slug'], next);
|
|
|
|
|
},
|
|
|
|
|
function (categoryData, next) {
|
2016-10-13 11:43:39 +02:00
|
|
|
categoryData = categoryData.map(function (category) {
|
2015-12-29 10:46:57 +02:00
|
|
|
return {
|
|
|
|
|
route: 'category/' + category.slug,
|
2017-02-17 19:31:21 -07:00
|
|
|
name: 'Category: ' + category.name,
|
2015-12-29 10:46:57 +02:00
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
2016-04-22 19:48:41 +03:00
|
|
|
categoryData = categoryData || [];
|
2015-12-29 10:46:57 +02:00
|
|
|
|
2017-02-18 12:30:49 -07:00
|
|
|
plugins.fireHook('filter:homepage.get', { routes: [
|
2016-04-22 19:48:41 +03:00
|
|
|
{
|
|
|
|
|
route: 'categories',
|
2017-02-17 19:31:21 -07:00
|
|
|
name: 'Categories',
|
2016-04-22 19:48:41 +03:00
|
|
|
},
|
2016-07-15 12:39:54 +03:00
|
|
|
{
|
|
|
|
|
route: 'unread',
|
2017-02-17 19:31:21 -07:00
|
|
|
name: 'Unread',
|
2016-07-15 12:39:54 +03:00
|
|
|
},
|
2016-04-22 19:48:41 +03:00
|
|
|
{
|
|
|
|
|
route: 'recent',
|
2017-02-17 19:31:21 -07:00
|
|
|
name: 'Recent',
|
2016-04-22 19:48:41 +03:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
route: 'popular',
|
2017-02-17 19:31:21 -07:00
|
|
|
name: 'Popular',
|
|
|
|
|
},
|
2017-02-18 12:30:49 -07:00
|
|
|
].concat(categoryData) }, next);
|
2016-04-22 19:48:41 +03:00
|
|
|
},
|
|
|
|
|
function (data, next) {
|
|
|
|
|
next(null, data.routes);
|
2017-02-17 19:31:21 -07:00
|
|
|
},
|
2016-04-22 19:48:41 +03:00
|
|
|
], callback);
|
2015-12-29 10:46:57 +02:00
|
|
|
}
|
|
|
|
|
|
2015-09-25 13:11:11 -04:00
|
|
|
|
2017-02-18 02:30:48 -07:00
|
|
|
module.exports = settingsController;
|