fixed favouriting

v1.18.x
Baris Usakli 12 years ago
parent e24606ff73
commit 38663177b0

@ -1,4 +1,5 @@
var RDB = require('./redis.js'), var RDB = require('./redis.js'),
posts = require('./posts.js'),
user = require('./user.js'); user = require('./user.js');
(function(Favourites) { (function(Favourites) {
@ -20,15 +21,15 @@ var RDB = require('./redis.js'),
return; return;
} }
RDB.get('pid:' + pid + ':uid', function(err, uid_of_poster) { posts.getPostField(pid, 'uid', function(uid_of_poster) {
RDB.handle(err);
Favourites.hasFavourited(pid, uid, function(hasFavourited) { Favourites.hasFavourited(pid, uid, function(hasFavourited) {
if (hasFavourited == false) { if (hasFavourited == false) {
RDB.sadd('pid:' + pid + ':users_favourited', uid); 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) { if (room_id) {
io.sockets.in(room_id).emit('event:rep_up', {uid: uid !== uid_of_poster ? uid_of_poster : 0, pid: pid}); 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; return;
} }
RDB.get('pid:' + pid + ':uid', function(err, uid_of_poster) { posts.getPostField(pid, 'uid', function(uid_of_poster) {
RDB.handle(err);
Favourites.hasFavourited(pid, uid, function(hasFavourited) { Favourites.hasFavourited(pid, uid, function(hasFavourited) {
if (hasFavourited == true) { if (hasFavourited == true) {
RDB.srem('pid:' + pid + ':users_favourited', uid); 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) { if (room_id) {
io.sockets.in(room_id).emit('event:rep_down', {uid: uid !== uid_of_poster ? uid_of_poster : 0, pid: pid}); io.sockets.in(room_id).emit('event:rep_down', {uid: uid !== uid_of_poster ? uid_of_poster : 0, pid: pid});

@ -255,10 +255,10 @@ var user = require('./../user.js'),
if (!req.params.section && !req.params.userslug) { if (!req.params.section && !req.params.userslug) {
user.getUserList(function(data) { user.getUserList(function(data) {
data = data.sort(function(a, b) { data = data.sort(function(a, b) {
return b.joindate - a.joindate; return b.joindate - a.joindate;
}); });
res.json({search_display: 'none', users:data}); res.json({search_display: 'none', users:data});
}); });
} }
else if(String(req.params.section).toLowerCase() === 'following') { else if(String(req.params.section).toLowerCase() === 'following') {

Loading…
Cancel
Save