From b50b5e4787c988fed89b018d10064279311fffe7 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Thu, 14 Aug 2014 17:59:33 -0400 Subject: [PATCH] satifying my OCD fire hook after successful follow/unfollow --- src/socket.io/user.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/socket.io/user.js b/src/socket.io/user.js index 04a37313db..5597a03b3a 100644 --- a/src/socket.io/user.js +++ b/src/socket.io/user.js @@ -162,26 +162,29 @@ SocketUser.changePicture = function(socket, data, callback) { SocketUser.follow = function(socket, data, callback) { if (socket.uid && data) { - plugins.fireHook('action:user.follow', { - fromUid: socket.uid, - toUid: data.uid - }); - - user.follow(socket.uid, data.uid, callback); + toggleFollow('follow', socket.uid, data.uid, callback); } }; SocketUser.unfollow = function(socket, data, callback) { if (socket.uid && data) { - plugins.fireHook('action:user.unfollow', { - fromUid: socket.uid, - toUid: data.uid - }); - - user.unfollow(socket.uid, data.uid, callback); + toggleFollow('unfollow', socket.uid, data.uid, callback); } }; +function toggleFollow(method, uid, theiruid, callback) { + user[method](uid, theiruid, function(err) { + if (err) { + return callback(err); + } + + plugins.fireHook('action:user.' + method, { + fromUid: uid, + toUid: theiruid + }); + }); +} + SocketUser.getSettings = function(socket, data, callback) { if (socket.uid) { if (socket.uid === parseInt(data.uid, 10)) {