From 6a4dd5cc057f3d7f64d5f99d271ae9c6c92e971b Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 18 Mar 2014 14:11:26 -0400 Subject: [PATCH] closes #1160 --- src/user/settings.js | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/user/settings.js b/src/user/settings.js index af1bf9e81b..79b5250bd2 100644 --- a/src/user/settings.js +++ b/src/user/settings.js @@ -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,