From e459592ac9cd84d07c391e5ef44298fad1409ddd Mon Sep 17 00:00:00 2001 From: barisusakli Date: Thu, 24 Jul 2014 16:12:53 -0400 Subject: [PATCH] closes #1893 --- src/threadTools.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/threadTools.js b/src/threadTools.js index 5539af3b39..5e52d043c7 100644 --- a/src/threadTools.js +++ b/src/threadTools.js @@ -221,17 +221,23 @@ var winston = require('winston'), }; ThreadTools.toggleFollow = function(tid, uid, callback) { - topics.isFollowing(tid, uid, function(err, following) { - if (err) { - return callback(err); - } - - db[following ? 'setRemove' : 'setAdd']('tid:' + tid + ':followers', uid, function(err) { - if (typeof callback === 'function') { - callback(err, !following); + callback = callback || function() {}; + async.waterfall([ + function (next) { + ThreadTools.exists(tid, next); + }, + function (exists, next) { + if (!exists) { + return next(new Error('[[error:no-topic]]')); } - }); - }); + topics.isFollowing(tid, uid, next); + }, + function (isFollowing, next) { + db[isFollowing ? 'setRemove' : 'setAdd']('tid:' + tid + ':followers', uid, function(err) { + next(err, !isFollowing); + }); + } + ], callback); }; }(exports));