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

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

Loading…
Cancel
Save