diff --git a/src/favourites.js b/src/favourites.js index 675a9fa285..c2cf33b391 100644 --- a/src/favourites.js +++ b/src/favourites.js @@ -1,4 +1,5 @@ var RDB = require('./redis.js'), + posts = require('./posts.js'), user = require('./user.js'); (function(Favourites) { @@ -20,15 +21,15 @@ var RDB = require('./redis.js'), return; } - RDB.get('pid:' + pid + ':uid', function(err, uid_of_poster) { - RDB.handle(err); + posts.getPostField(pid, 'uid', function(uid_of_poster) { Favourites.hasFavourited(pid, uid, function(hasFavourited) { if (hasFavourited == false) { RDB.sadd('pid:' + pid + ':users_favourited', uid); - RDB.incr('pid:' + pid + ':rep'); + RDB.hincrby('post:' + pid, 'reputation', 1); - if (uid !== uid_of_poster) user.incrementUserFieldBy(uid_of_poster, 'reputation', 1); + if (uid !== uid_of_poster) + user.incrementUserFieldBy(uid_of_poster, 'reputation', 1); if (room_id) { io.sockets.in(room_id).emit('event:rep_up', {uid: uid !== uid_of_poster ? uid_of_poster : 0, pid: pid}); @@ -54,16 +55,16 @@ var RDB = require('./redis.js'), return; } - RDB.get('pid:' + pid + ':uid', function(err, uid_of_poster) { - RDB.handle(err); + posts.getPostField(pid, 'uid', function(uid_of_poster) { Favourites.hasFavourited(pid, uid, function(hasFavourited) { if (hasFavourited == true) { RDB.srem('pid:' + pid + ':users_favourited', uid); - RDB.decr('pid:' + pid + ':rep'); + RDB.hincrby('post:' + pid, 'reputation', -1); - if (uid !== uid_of_poster) user.incrementUserFieldBy(uid_of_poster, 'reputation', -1); + if (uid !== uid_of_poster) + user.incrementUserFieldBy(uid_of_poster, 'reputation', -1); if (room_id) { io.sockets.in(room_id).emit('event:rep_down', {uid: uid !== uid_of_poster ? uid_of_poster : 0, pid: pid}); diff --git a/src/routes/user.js b/src/routes/user.js index 7921124fa7..d4111570de 100644 --- a/src/routes/user.js +++ b/src/routes/user.js @@ -255,10 +255,10 @@ var user = require('./../user.js'), if (!req.params.section && !req.params.userslug) { user.getUserList(function(data) { - data = data.sort(function(a, b) { - return b.joindate - a.joindate; - }); - res.json({search_display: 'none', users:data}); + data = data.sort(function(a, b) { + return b.joindate - a.joindate; + }); + res.json({search_display: 'none', users:data}); }); } else if(String(req.params.section).toLowerCase() === 'following') {