fixed favouriting

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

@ -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});

@ -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') {

Loading…
Cancel
Save