v1.18.x
barisusakli 11 years ago
parent e11efad0b7
commit 6a4dd5cc05

@ -2,24 +2,12 @@
'use strict';
var meta = require('./../meta'),
db = require('./../database');
db = require('./../database'),
plugins = require('./../plugins');
module.exports = function(User) {
User.getSettings = function(uid, callback) {
function sendDefaultSettings() {
callback(null, {
showemail: false,
usePagination: parseInt(meta.config.usePagination, 10) === 1,
topicsPerPage: parseInt(meta.config.topicsPerPage, 10) || 20,
postsPerPage: parseInt(meta.config.postsPerPage, 10) || 10
});
}
if(!parseInt(uid, 10)) {
return sendDefaultSettings();
}
db.getObject('user:' + uid + ':settings', function(err, settings) {
if(err) {
return callback(err);
@ -29,12 +17,20 @@ module.exports = function(User) {
settings = {};
}
settings.showemail = settings.showemail ? parseInt(settings.showemail, 10) !== 0 : false;
settings.usePagination = settings.usePagination ? parseInt(settings.usePagination, 10) === 1 : parseInt(meta.config.usePagination, 10) === 1;
settings.topicsPerPage = settings.topicsPerPage ? parseInt(settings.topicsPerPage, 10) : parseInt(meta.config.topicsPerPage, 10) || 20;
settings.postsPerPage = settings.postsPerPage ? parseInt(settings.postsPerPage, 10) : parseInt(meta.config.postsPerPage, 10) || 10;
plugins.fireHook('filter:user.getSettings', {uid: uid, settings: settings}, function(err, data) {
if(err) {
return callback(err);
}
callback(null, settings);
settings = data.settings;
settings.showemail = settings.showemail ? parseInt(settings.showemail, 10) !== 0 : false;
settings.usePagination = settings.usePagination ? parseInt(settings.usePagination, 10) === 1 : parseInt(meta.config.usePagination, 10) === 1;
settings.topicsPerPage = settings.topicsPerPage ? parseInt(settings.topicsPerPage, 10) : parseInt(meta.config.topicsPerPage, 10) || 20;
settings.postsPerPage = settings.postsPerPage ? parseInt(settings.postsPerPage, 10) : parseInt(meta.config.postsPerPage, 10) || 10;
callback(null, settings);
});
});
};
@ -44,6 +40,8 @@ module.exports = function(User) {
return callback(new Error('Invalid pagination value!'));
}
plugins.fireHook('action:user.saveSettings', {uid: uid, settings: data});
db.setObject('user:' + uid + ':settings', {
showemail: data.showemail,
usePagination: data.usePagination,

Loading…
Cancel
Save