From bf918bd016f645b9d307e4314943f787082b8627 Mon Sep 17 00:00:00 2001 From: James Holding Date: Sun, 25 Oct 2015 10:14:00 +0000 Subject: [PATCH 01/18] Upgrade script fails on some consoles The upgrade script errors/fails on some consoles if the stdout.columns isn't set (my console did this when upgrading a Docker instance of NodeBB). Checking for stdout.columns before using, falling back to a couple of spaces for slightly prettiness if we can't work out the console width. --- nodebb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nodebb b/nodebb index db9dcbe425..01aa843a18 100755 --- a/nodebb +++ b/nodebb @@ -144,8 +144,10 @@ switch(process.argv[2]) { if (err) { process.stdout.write('\nError'.red + ': ' + err.message + '\n'); } else { - var message = 'NodeBB Upgrade Complete!', - spaces = new Array(Math.floor(process.stdout.columns / 2) - (message.length / 2) + 1).join(' '); + var message = 'NodeBB Upgrade Complete!'; + // some consoles will return undefined/zero columns, so just use 2 spaces in upgrade script if we can't get our column count + var columns = process.stdout.columns; + var spaces = columns ? new Array(Math.floor(columns / 2) - (message.length / 2) + 1).join(' ') : " "; process.stdout.write('OK\n'.green); process.stdout.write('\n' + spaces + message.green.bold + '\n\n'.reset); From aafd4b698456864fb41c365d3202a7890643fd72 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sun, 25 Oct 2015 15:56:17 -0400 Subject: [PATCH 02/18] closes #3786 --- public/src/client/topic/fork.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/src/client/topic/fork.js b/public/src/client/topic/fork.js index 7a3aa8e3ac..8e95ee6d9a 100644 --- a/public/src/client/topic/fork.js +++ b/public/src/client/topic/fork.js @@ -10,7 +10,7 @@ define('forum/topic/fork', ['components'], function(components) { pids = []; Fork.init = function() { - components.get('topic/fork').on('click', onForkThreadClicked); + $('.topic').on('click', '[component="topic/fork"]', onForkThreadClicked); }; function disableClicks() { From 9bc43ba5e1e8ca145615bd07fff1560bc7f3eb6e Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sun, 25 Oct 2015 16:57:42 -0400 Subject: [PATCH 03/18] closes #3788 --- src/messaging.js | 14 +++++--------- src/routes/index.js | 4 ++-- src/views/500-embed.tpl | 9 +++++++++ src/views/500.tpl | 3 --- 4 files changed, 16 insertions(+), 14 deletions(-) create mode 100644 src/views/500-embed.tpl diff --git a/src/messaging.js b/src/messaging.js index 7609ad24f9..0631de61f8 100644 --- a/src/messaging.js +++ b/src/messaging.js @@ -374,12 +374,8 @@ var db = require('./database'), }; Messaging.canMessage = function(fromUid, toUid, callback) { - if (parseInt(meta.config.disableChat) === 1) { - return callback(new Error('[[error:chat-disabled]]')); - } else if (toUid === fromUid) { - return callback(new Error('[[error:cant-chat-with-yourself]]')); - } else if (!fromUid) { - return callback(new Error('[[error:not-logged-in]]')); + if (parseInt(meta.config.disableChat) === 1 || !fromUid || toUid === fromUid) { + return callback(null, false); } async.waterfall([ @@ -388,17 +384,17 @@ var db = require('./database'), }, function (exists, next) { if (!exists) { - return next(new Error('[[error:no-user]]')); + return callback(null, false); } user.getUserFields(fromUid, ['banned', 'email:confirmed'], next); }, function (userData, next) { if (parseInt(userData.banned, 10) === 1) { - return next(new Error('[[error:user-banned]]')); + return callback(null, false); } if (parseInt(meta.config.requireEmailConfirmation, 10) === 1 && parseInt(userData['email:confirmed'], 10) !== 1) { - return next(new Error('[[error:email-not-confirmed-chat]]')); + return callback(null, false); } user.getSettings(toUid, next); diff --git a/src/routes/index.js b/src/routes/index.js index 57a8c8134a..8d011f7f5a 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -175,7 +175,7 @@ function handle404(app, middleware) { } function handleErrors(app, middleware) { - app.use(function(err, req, res) { + app.use(function(err, req, res, next) { if (err.code === 'EBADCSRFTOKEN') { winston.error(req.path + '\n', err.message); return res.sendStatus(403); @@ -190,7 +190,7 @@ function handleErrors(app, middleware) { res.status(err.status || 500); if (res.locals.isAPI) { - return res.json({path: req.path, error: err.message}); + res.json({path: req.path, error: err.message}); } else { middleware.buildHeader(req, res, function() { res.render('500', {path: req.path, error: err.message}); diff --git a/src/views/500-embed.tpl b/src/views/500-embed.tpl new file mode 100644 index 0000000000..537cbac136 --- /dev/null +++ b/src/views/500-embed.tpl @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/src/views/500.tpl b/src/views/500.tpl index 537cbac136..3abb9e8e27 100644 --- a/src/views/500.tpl +++ b/src/views/500.tpl @@ -1,9 +1,6 @@ - \ No newline at end of file From 0d88d52557bf187c3b4d2b78f6da49d52952e9d1 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sun, 25 Oct 2015 17:03:33 -0400 Subject: [PATCH 04/18] up theme --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c5f76cfd9a..d3cb070060 100644 --- a/package.json +++ b/package.json @@ -49,8 +49,8 @@ "nodebb-plugin-spam-be-gone": "0.4.2", "nodebb-rewards-essentials": "0.0.5", "nodebb-theme-lavender": "2.0.10", - "nodebb-theme-persona": "3.0.61", - "nodebb-theme-vanilla": "4.0.28", + "nodebb-theme-persona": "3.0.62", + "nodebb-theme-vanilla": "4.0.29", "nodebb-widget-essentials": "2.0.3", "npm": "^2.1.4", "passport": "^0.3.0", From 5820a193f60bcf0398ab1f981192cc1908f277cc Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sun, 25 Oct 2015 17:04:46 -0400 Subject: [PATCH 05/18] closes #3789 --- src/user/digest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/user/digest.js b/src/user/digest.js index da639fc0b8..f9d4a1092c 100644 --- a/src/user/digest.js +++ b/src/user/digest.js @@ -98,7 +98,7 @@ var async = require('async'), } for(var i=0; i Date: Sun, 25 Oct 2015 21:54:35 -0400 Subject: [PATCH 06/18] add back thread tools filter --- src/socket.io/topics/tools.js | 44 ++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/socket.io/topics/tools.js b/src/socket.io/topics/tools.js index 38a80c356c..35e1118986 100644 --- a/src/socket.io/topics/tools.js +++ b/src/socket.io/topics/tools.js @@ -4,6 +4,7 @@ var async = require('async'); var topics = require('../../topics'); var events = require('../../events'); var privileges = require('../../privileges'); +var plugins = require('../../plugins'); var socketHelpers = require('../helpers'); module.exports = function(SocketTopics) { @@ -13,28 +14,33 @@ module.exports = function(SocketTopics) { return; } if (!data) { - return callback(new Error('[[error:invalid-data]]')) + return callback(new Error('[[error:invalid-data]]')); } - - async.parallel({ - topic: function(next) { - topics.getTopicFields(data.tid, ['deleted', 'locked', 'pinned'], next); + var topic; + async.waterfall([ + function (next) { + async.parallel({ + topic: function(next) { + topics.getTopicData(data.tid, next); + }, + privileges: function(next) { + privileges.topics.get(data.tid, socket.uid, next); + } + }, next); }, - privileges: function(next) { - privileges.topics.get(data.tid, socket.uid, next); - } - }, function(err, results) { - if (err) { - return callback(err); + function (results, next) { + topic = results.topic; + topic.privileges = results.privileges; + plugins.fireHook('filter:topic.thread_tools', {topic: results.topic, uid: socket.uid, tools: []}, next); + }, + function (data, next) { + topic.deleted = parseInt(topic.deleted, 10) === 1; + topic.locked = parseInt(topic.locked, 10) === 1; + topic.pinned = parseInt(topic.pinned, 10) === 1; + topic.thread_tools = data.tools; + next(null, topic); } - - results.topic.deleted = parseInt(results.topic.deleted, 10) === 1; - results.topic.locked = parseInt(results.topic.locked, 10) === 1; - results.topic.pinned = parseInt(results.topic.pinned, 10) === 1; - results.topic.privileges = results.privileges; - - callback(null, results.topic); - }); + ], callback); }; SocketTopics.delete = function(socket, data, callback) { From e0e04ef8920e61f3bf411903b5a5c1f5198e1698 Mon Sep 17 00:00:00 2001 From: Christian Nolte Date: Mon, 26 Oct 2015 14:50:32 +0100 Subject: [PATCH 07/18] Fixed wrong method name in socket.io/groups.js from isAdmin to isAdministrator --- src/socket.io/groups.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/socket.io/groups.js b/src/socket.io/groups.js index 1a07a90c26..9807e821b8 100644 --- a/src/socket.io/groups.js +++ b/src/socket.io/groups.js @@ -63,7 +63,7 @@ SocketGroups.leave = function(socket, data, callback) { function isOwner(next) { return function (socket, data, callback) { async.parallel({ - isAdmin: async.apply(user.isAdmin, socket.uid), + isAdmin: async.apply(user.isAdministrator, socket.uid), isOwner: async.apply(groups.ownership.isOwner, socket.uid, data.groupName) }, function(err, results) { if (err || (!isOwner && !results.isAdmin)) { From 5454862c1c81525bb096466a547557cfb0f9a2b7 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Mon, 26 Oct 2015 20:26:02 -0400 Subject: [PATCH 08/18] wait for all callbacks when creating tags --- src/topics/tags.js | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/topics/tags.js b/src/topics/tags.js index 54514ddc42..e971f1b237 100644 --- a/src/topics/tags.js +++ b/src/topics/tags.js @@ -18,29 +18,31 @@ module.exports = function(Topics) { return callback(); } - plugins.fireHook('filter:tags.filter', {tags: tags, tid: tid}, function(err, data) { - if (err) { - return callback(err); - } - - tags = data.tags.slice(0, meta.config.maximumTagsPerTopic || 5); - - async.each(tags, function(tag, next) { - tag = Topics.cleanUpTag(tag); - - if (tag.length < (meta.config.minimumTagLength || 3)) { - return next(); - } - db.setAdd('topic:' + tid + ':tags', tag); + async.waterfall([ + function (next) { + plugins.fireHook('filter:tags.filter', {tags: tags, tid: tid}, next); + }, + function (data, next) { + tags = data.tags.slice(0, meta.config.maximumTagsPerTopic || 5); - db.sortedSetAdd('tag:' + tag + ':topics', timestamp, tid, function(err) { - if (!err) { - updateTagCount(tag); + async.each(tags, function(tag, next) { + tag = Topics.cleanUpTag(tag); + if (tag.length < (meta.config.minimumTagLength || 3)) { + return next(); } - next(err); - }); - }, callback); - }); + + async.parallel([ + async.apply(db.setAdd, 'topic:' + tid + ':tags', tag), + async.apply(db.sortedSetAdd, 'tag:' + tag + ':topics', timestamp, tid) + ], function(err) { + if (err) { + return next(err); + } + updateTagCount(tag, next); + }); + }, next); + } + ], callback); }; Topics.cleanUpTag = function(tag) { From 555c5b82da3ee30eab3fb21b2474eba834556741 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Mon, 26 Oct 2015 21:19:20 -0400 Subject: [PATCH 09/18] check user settings --- src/posts/user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/posts/user.js b/src/posts/user.js index 817edda518..1a82ab9591 100644 --- a/src/posts/user.js +++ b/src/posts/user.js @@ -43,7 +43,7 @@ module.exports = function(Posts) { userTitle: group.userTitle }; - if (group.name === results.userSettings[i].groupTitle && group.userTitleEnabled) { + if (results.userSettings[i] && group.name === results.userSettings[i].groupTitle && group.userTitleEnabled) { userData.selectedGroup = userData.groups[index]; } }); From 57d39802671612185e86977b5c237f850fe80206 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Mon, 26 Oct 2015 22:16:08 -0400 Subject: [PATCH 10/18] closes #3790 --- src/navigation/admin.js | 13 +++++-------- src/navigation/index.js | 13 +++++++++---- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/navigation/admin.js b/src/navigation/admin.js index b66982a310..a803b5465b 100644 --- a/src/navigation/admin.js +++ b/src/navigation/admin.js @@ -7,7 +7,7 @@ var admin = {}, db = require('../database'), translator = require('../../public/src/modules/translator'); -var navigationCache = null; +admin.cache = null; admin.save = function(data, callback) { var order = Object.keys(data), @@ -24,7 +24,7 @@ admin.save = function(data, callback) { return JSON.stringify(data); }); - navigationCache = null; + admin.cache = null; async.waterfall([ function(next) { db.delete('navigation:enabled', next); @@ -43,19 +43,16 @@ admin.getAdmin = function(callback) { }; admin.get = function(callback) { - if (navigationCache) { - return callback(null, navigationCache); - } - db.getSortedSetRange('navigation:enabled', 0, -1, function(err, data) { if (err) { return callback(err); } - navigationCache = data.map(function(item, idx) { + + data = data.map(function(item, idx) { return JSON.parse(item)[idx]; }); - callback(null, navigationCache); + callback(null, data); }); }; diff --git a/src/navigation/index.js b/src/navigation/index.js index 7d536dcca9..14bb1c0f41 100644 --- a/src/navigation/index.js +++ b/src/navigation/index.js @@ -1,12 +1,15 @@ "use strict"; -var navigation = {}, - admin = require('./admin'), - translator = require('../../public/src/modules/translator'); - +var navigation = {}; +var admin = require('./admin'); +var translator = require('../../public/src/modules/translator'); navigation.get = function(callback) { + if (admin.cache) { + return callback(null, admin.cache); + } + admin.get(function(err, data) { if (err) { return callback(err); @@ -23,6 +26,8 @@ navigation.get = function(callback) { return item; }); + admin.cache = data; + callback(null, data); }); }; From 5e1bd58a022b1aaeedd7ab83c3655b3c16c611a0 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Mon, 26 Oct 2015 22:28:30 -0400 Subject: [PATCH 11/18] closes #3782 --- src/privileges/categories.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/privileges/categories.js b/src/privileges/categories.js index fa03bca51b..31d1deeeb3 100644 --- a/src/privileges/categories.js +++ b/src/privileges/categories.js @@ -101,7 +101,12 @@ module.exports = function(privileges) { }); groupNames = groups.getEphemeralGroups().concat(groupNames); - groupNames.splice(0, 0, groupNames.splice(groupNames.indexOf('registered-users'), 1)[0]); + var registeredUsersIndex = groupNames.indexOf('registered-users'); + if (registeredUsersIndex !== -1) { + groupNames.splice(0, 0, groupNames.splice(registeredUsersIndex, 1)[0]); + } else { + groupNames = ['registered-users'].concat(groupNames); + } var adminIndex = groupNames.indexOf('administrators'); if (adminIndex !== -1) { From 488f147bef395233edb697a3895df0da7ee5ed0d Mon Sep 17 00:00:00 2001 From: barisusakli Date: Mon, 26 Oct 2015 22:39:19 -0400 Subject: [PATCH 12/18] closes #3781 --- package.json | 2 +- src/controllers/index.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d3cb070060..bd436082f9 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "rss": "^1.0.0", "semver": "^5.0.1", "serve-favicon": "^2.1.5", - "sitemap": "^1.0.0", + "sitemap": "^1.4.0", "socket.io": "^1.2.1", "socket.io-client": "^1.2.1", "socket.io-redis": "^0.1.3", diff --git a/src/controllers/index.js b/src/controllers/index.js index 3b364ebf9e..fec9b23c01 100644 --- a/src/controllers/index.js +++ b/src/controllers/index.js @@ -168,7 +168,10 @@ Controllers.sitemap = function(req, res, next) { var sitemap = require('../sitemap.js'); - sitemap.render(function(xml) { + sitemap.render(function(err, xml) { + if (err) { + return next(err); + } res.header('Content-Type', 'application/xml'); res.send(xml); }); From 7ee584b6327ea79f4b1f465c32da28d01c75908f Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 27 Oct 2015 01:43:06 -0400 Subject: [PATCH 13/18] If notification dropdown is double-clicked, all notifications are marked read --- public/src/modules/notifications.js | 39 ++++++++++++++++++----------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/public/src/modules/notifications.js b/public/src/modules/notifications.js index cb6a4ef04e..d3579b60ae 100644 --- a/public/src/modules/notifications.js +++ b/public/src/modules/notifications.js @@ -11,14 +11,21 @@ define('notifications', ['sounds', 'translator', 'components'], function(sound, notifList = components.get('notifications/list'), notifIcon = components.get('notifications/icon'); - notifTrigger.on('click', function(e) { - e.preventDefault(); - if (notifContainer.hasClass('open')) { - return; - } + notifTrigger + .on('click', function(e) { + e.preventDefault(); + if (notifContainer.hasClass('open')) { + return; + } - Notifications.loadNotifications(notifList); - }); + Notifications.loadNotifications(notifList); + }) + .on('dblclick', function(e) { + e.preventDefault(); + if (parseInt(notifIcon.attr('data-content'), 10) > 0) { + Notifications.markAllRead(); + } + }); notifList.on('click', '[data-nid]', function() { var unread = $(this).hasClass('unread'); @@ -33,14 +40,7 @@ define('notifications', ['sounds', 'translator', 'components'], function(sound, }); }); - notifContainer.on('click', '.mark-all-read', function() { - socket.emit('notifications.markAllRead', function(err) { - if (err) { - app.alertError(err.message); - } - Notifications.updateNotifCount(0); - }); - }); + notifContainer.on('click', '.mark-all-read', Notifications.markAllRead); notifList.on('click', '.mark-read', function(e) { var liEl = $(this).parent(), @@ -125,5 +125,14 @@ define('notifications', ['sounds', 'translator', 'components'], function(sound, Tinycon.setBubble(count); }; + Notifications.markAllRead = function() { + socket.emit('notifications.markAllRead', function(err) { + if (err) { + app.alertError(err.message); + } + Notifications.updateNotifCount(0); + }); + }; + return Notifications; }); From 4ef2ae7ba2dad88312ec375cf3848b78e90a9bc4 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 27 Oct 2015 14:01:13 -0400 Subject: [PATCH 14/18] update count even if its 0 --- src/topics/tags.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/topics/tags.js b/src/topics/tags.js index e971f1b237..ef4fb04290 100644 --- a/src/topics/tags.js +++ b/src/topics/tags.js @@ -66,9 +66,10 @@ module.exports = function(Topics) { function updateTagCount(tag, callback) { callback = callback || function() {}; Topics.getTagTopicCount(tag, function(err, count) { - if (err || !count) { + if (err) { return callback(err); } + count = count || 0; db.sortedSetAdd('tags:topic:count', count, tag, callback); }); From efef0af6fa2d7ff5840076b8d95863516330414d Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 27 Oct 2015 15:04:46 -0400 Subject: [PATCH 15/18] tag fix --- src/topics/tags.js | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/topics/tags.js b/src/topics/tags.js index ef4fb04290..7fcda9dfff 100644 --- a/src/topics/tags.js +++ b/src/topics/tags.js @@ -25,22 +25,23 @@ module.exports = function(Topics) { function (data, next) { tags = data.tags.slice(0, meta.config.maximumTagsPerTopic || 5); - async.each(tags, function(tag, next) { - tag = Topics.cleanUpTag(tag); - if (tag.length < (meta.config.minimumTagLength || 3)) { - return next(); - } + tags = tags.map(Topics.cleanUpTag).filter(function(tag) { + return tag && tag.length >= (meta.config.minimumTagLength || 3); + }); - async.parallel([ - async.apply(db.setAdd, 'topic:' + tid + ':tags', tag), - async.apply(db.sortedSetAdd, 'tag:' + tag + ':topics', timestamp, tid) - ], function(err) { - if (err) { - return next(err); - } - updateTagCount(tag, next); - }); - }, next); + var keys = tags.map(function(tag) { + return 'tag:' + tag + ':topics'; + }); + + async.parallel([ + async.apply(db.setAdd, 'topic:' + tid + ':tags', tags), + async.apply(db.sortedSetsAdd, keys, timestamp, tid) + ], function(err) { + if (err) { + return next(err); + } + async.each(tags, updateTagCount, next); + }); } ], callback); }; From 353ebb71d22fb27044e04bbd7e9491cf6f8140ee Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 27 Oct 2015 17:03:14 -0400 Subject: [PATCH 16/18] removed unnecessary if --- src/controllers/topics.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/controllers/topics.js b/src/controllers/topics.js index af62540ff6..6dbbb79ec5 100644 --- a/src/controllers/topics.js +++ b/src/controllers/topics.js @@ -72,9 +72,7 @@ topicsController.get = function(req, res, callback) { reverse = false; // `sort` qs has priority over user setting - if (sort === 'oldest_to_newest') { - reverse = false; - } else if (sort === 'newest_to_oldest') { + if (sort === 'newest_to_oldest') { reverse = true; } else if (sort === 'most_votes') { reverse = true; From 96befd02adb0f8e5f56fda24928756d78d692d70 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 27 Oct 2015 17:06:20 -0400 Subject: [PATCH 17/18] up markdown --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bd436082f9..526d901336 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "nodebb-plugin-composer-default": "1.0.20", "nodebb-plugin-dbsearch": "0.2.17", "nodebb-plugin-emoji-extended": "0.4.15", - "nodebb-plugin-markdown": "4.0.6", + "nodebb-plugin-markdown": "4.0.7", "nodebb-plugin-mentions": "1.0.8", "nodebb-plugin-soundpack-default": "0.1.4", "nodebb-plugin-spam-be-gone": "0.4.2", From 290686a194a410a5fa6fc1cfd5e4504e3a9baa32 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 27 Oct 2015 17:21:28 -0400 Subject: [PATCH 18/18] modifyCategory is no longer async --- src/categories/data.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/categories/data.js b/src/categories/data.js index cccacc8a68..5cfdb091b2 100644 --- a/src/categories/data.js +++ b/src/categories/data.js @@ -5,13 +5,17 @@ var validator = require('validator'); var winston = require('winston'); var db = require('../database'); -var plugins = require('../plugins'); module.exports = function(Categories) { Categories.getCategoryData = function(cid, callback) { - Categories.getCategoriesData([cid], function(err, categories) { - callback(err, categories ? categories[0] : null); + db.getObject('category:' + cid, function(err, category) { + if (err) { + return callback(err); + } + + modifyCategory(category); + callback(null, category); }); }; @@ -28,13 +32,14 @@ module.exports = function(Categories) { return callback(err, []); } - async.map(categories, modifyCategory, callback); + categories.forEach(modifyCategory); + callback(null, categories); }); }; - function modifyCategory(category, callback) { + function modifyCategory(category) { if (!category) { - return callback(null, null); + return; } category.name = validator.escape(category.name); @@ -56,8 +61,6 @@ module.exports = function(Categories) { category.description = validator.escape(category.description); category.descriptionParsed = category.descriptionParsed || category.description; } - - callback(null, category); } Categories.getCategoryField = function(cid, field, callback) { @@ -77,7 +80,9 @@ module.exports = function(Categories) { if (err) { return callback(err); } - async.map(categories, modifyCategory, callback); + + categories.forEach(modifyCategory); + callback(null, categories); }); };