From bd94fbc2b13382eb2e67e4bf4888069ebb3c6af9 Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Fri, 10 May 2019 12:41:40 -0400 Subject: [PATCH] feat: let theme know downvoting is disabled, closes https://github.com/NodeBB/NodeBB/pull/7568 dont load downvote data if downvoting is disabled --- src/socket.io/posts/votes.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/socket.io/posts/votes.js b/src/socket.io/posts/votes.js index 29535641ea..c357c2beca 100644 --- a/src/socket.io/posts/votes.js +++ b/src/socket.io/posts/votes.js @@ -14,7 +14,7 @@ module.exports = function (SocketPosts) { if (!data || !data.pid || !data.cid) { return callback(new Error('[[error:invalid-data]]')); } - + const showDownvotes = !meta.config['downvote:disabled']; async.waterfall([ function (next) { if (meta.config.votesArePublic) { @@ -32,6 +32,9 @@ module.exports = function (SocketPosts) { db.getSetMembers('pid:' + data.pid + ':upvote', next); }, downvoteUids: function (next) { + if (!showDownvotes) { + return setImmediate(next, null, []); + } db.getSetMembers('pid:' + data.pid + ':downvote', next); }, }, next); @@ -41,17 +44,17 @@ module.exports = function (SocketPosts) { upvoters: function (next) { user.getUsersFields(results.upvoteUids, ['username', 'userslug', 'picture'], next); }, - upvoteCount: function (next) { - next(null, results.upvoteUids.length); - }, downvoters: function (next) { user.getUsersFields(results.downvoteUids, ['username', 'userslug', 'picture'], next); }, - downvoteCount: function (next) { - next(null, results.downvoteUids.length); - }, }, next); }, + function (results, next) { + results.upvoteCount = results.upvoters.length; + results.downvoteCount = results.downvoters.length; + results.showDownvotes = showDownvotes; + next(null, results); + } ], callback); };