From b060bda8a06676e21c6d70903d66d61fa97a21c9 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Thu, 2 Mar 2017 17:25:32 +0300 Subject: [PATCH] some more refactors --- src/groups.js | 21 +++++++++------------ src/user/profile.js | 26 ++++++++------------------ src/webserver.js | 27 ++++++++++++++------------- 3 files changed, 31 insertions(+), 43 deletions(-) diff --git a/src/groups.js b/src/groups.js index 7e2e216caa..fd8c4a958f 100644 --- a/src/groups.js +++ b/src/groups.js @@ -243,26 +243,23 @@ Groups.getGroupNameByGroupSlug = function (slug, callback) { }; Groups.isPrivate = function (groupName, callback) { - async.waterfall([ - function (next) { - db.getObjectField('group:' + groupName, 'private', next); - }, - function (isPrivate, next) { - next(null, parseInt(isPrivate, 10) !== 0); - }, - ], callback); + isFieldOn(groupName, 'private', callback); }; Groups.isHidden = function (groupName, callback) { + isFieldOn(groupName, 'hidden', callback); +}; + +function isFieldOn(groupName, field, callback) { async.waterfall([ function (next) { - db.getObjectField('group:' + groupName, 'hidden', next); + db.getObjectField('group:' + groupName, field, next); }, - function (isHidden, next) { - next(null, parseInt(isHidden, 10) === 1); + function (value, next) { + next(null, parseInt(value, 10) === 1); }, ], callback); -}; +} Groups.exists = function (name, callback) { if (Array.isArray(name)) { diff --git a/src/user/profile.js b/src/user/profile.js index b0d40cf02d..ab7d9f9ae2 100644 --- a/src/user/profile.js +++ b/src/user/profile.js @@ -15,6 +15,14 @@ module.exports = function (User) { var fields = ['username', 'email', 'fullname', 'website', 'location', 'groupTitle', 'birthday', 'signature', 'aboutme']; + if (data.aboutme !== undefined && data.aboutme.length > meta.config.maximumAboutMeLength) { + return callback(new Error('[[error:about-me-too-long, ' + meta.config.maximumAboutMeLength + ']]')); + } + + if (data.signature !== undefined && data.signature.length > meta.config.maximumSignatureLength) { + return callback(new Error('[[error:signature-too-long, ' + meta.config.maximumSignatureLength + ']]')); + } + async.waterfall([ function (next) { plugins.fireHook('filter:user.updateProfile', { uid: uid, data: data, fields: fields }, next); @@ -24,8 +32,6 @@ module.exports = function (User) { data = data.data; async.series([ - async.apply(isAboutMeValid, data), - async.apply(isSignatureValid, data), async.apply(isEmailAvailable, data, uid), async.apply(isUsernameAvailable, data, uid), async.apply(isGroupTitleValid, data), @@ -61,22 +67,6 @@ module.exports = function (User) { ], callback); }; - function isAboutMeValid(data, callback) { - if (data.aboutme !== undefined && data.aboutme.length > meta.config.maximumAboutMeLength) { - callback(new Error('[[error:about-me-too-long, ' + meta.config.maximumAboutMeLength + ']]')); - } else { - callback(); - } - } - - function isSignatureValid(data, callback) { - if (data.signature !== undefined && data.signature.length > meta.config.maximumSignatureLength) { - callback(new Error('[[error:signature-too-long, ' + meta.config.maximumSignatureLength + ']]')); - } else { - callback(); - } - } - function isEmailAvailable(data, uid, callback) { if (!data.email) { return callback(); diff --git a/src/webserver.js b/src/webserver.js index f3abeece54..e254d71008 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -61,21 +61,20 @@ module.exports.listen = function (callback) { logger.init(app); - initializeNodeBB(function (err) { - if (err) { - return callback(err); - } - - winston.info('NodeBB Ready'); + async.waterfall([ + initializeNodeBB, + function (next) { + winston.info('NodeBB Ready'); - require('./socket.io').server.emit('event:nodebb.ready', { - 'cache-buster': meta.config['cache-buster'], - }); + require('./socket.io').server.emit('event:nodebb.ready', { + 'cache-buster': meta.config['cache-buster'], + }); - plugins.fireHook('action:nodebb.ready'); + plugins.fireHook('action:nodebb.ready'); - listen(callback); - }); + listen(next); + }, + ], callback); }; function initializeNodeBB(callback) { @@ -107,7 +106,9 @@ function initializeNodeBB(callback) { meta.blacklist.load, ], next); }, - ], callback); + ], function (err) { + callback(err); + }); } function setupExpressApp(app) {