From 79ffae608e92f19391344467df63b6a3e44653aa Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Fri, 27 Jul 2018 12:58:01 -0400 Subject: [PATCH] closes #6675 --- src/socket.io/user/profile.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/socket.io/user/profile.js b/src/socket.io/user/profile.js index 036a22c366..14c4d5fbea 100644 --- a/src/socket.io/user/profile.js +++ b/src/socket.io/user/profile.js @@ -205,24 +205,29 @@ module.exports = function (SocketUser) { }; SocketUser.toggleBlock = function (socket, data, callback) { - let current; + let isBlocked; async.waterfall([ function (next) { - user.blocks.can(socket.uid, data.blockerUid, data.blockeeUid, next); + async.parallel({ + can: function (next) { + user.blocks.can(socket.uid, data.blockerUid, data.blockeeUid, next); + }, + is: function (next) { + user.blocks.is(data.blockeeUid, data.blockerUid, next); + } + }, next); }, - function (can, next) { - if (!can) { + function (results, next) { + isBlocked = results.is; + if (!results.can && !isBlocked) { return next(new Error('[[error:cannot-block-privileged]]')); } - user.blocks.is(data.blockeeUid, data.blockerUid, next); - }, - function (is, next) { - current = is; - user.blocks[is ? 'remove' : 'add'](data.blockeeUid, data.blockerUid, next); + + user.blocks[isBlocked ? 'remove' : 'add'](data.blockeeUid, data.blockerUid, next); }, ], function (err) { - callback(err, !current); + callback(err, !isBlocked); }); }; };