fix unfavourite

v1.18.x
barisusakli 10 years ago
parent 47c1092842
commit 671ec8532c

@ -24,7 +24,7 @@ module.exports = function(db, module) {
}, { }, {
upsert: true, upsert: true,
w: 1 w: 1
}, function(err) { }, function(err, res) {
callback(err); callback(err);
}); });
}; };
@ -54,7 +54,7 @@ module.exports = function(db, module) {
}}); }});
} }
bulk.execute(function(err) { bulk.execute(function(err, res) {
callback(err); callback(err);
}); });
}; };
@ -69,7 +69,9 @@ module.exports = function(db, module) {
array[index] = helpers.valueToString(element); array[index] = helpers.valueToString(element);
}); });
db.collection('objects').update({_key: key}, {$pullAll: {members: value}}, callback); db.collection('objects').update({_key: key}, {$pullAll: {members: value}}, function(err, res) {
callback(err);
});
}; };
module.setsRemove = function(keys, value, callback) { module.setsRemove = function(keys, value, callback) {

@ -3,7 +3,7 @@
module.exports = function(redisClient, module) { module.exports = function(redisClient, module) {
module.setAdd = function(key, value, callback) { module.setAdd = function(key, value, callback) {
callback = callback || function() {}; callback = callback || function() {};
redisClient.sadd(key, value, function(err) { redisClient.sadd(key, value, function(err, res) {
callback(err); callback(err);
}); });
}; };
@ -14,13 +14,15 @@ module.exports = function(redisClient, module) {
for (var i=0; i<keys.length; ++i) { for (var i=0; i<keys.length; ++i) {
multi.sadd(keys[i], value); multi.sadd(keys[i], value);
} }
multi.exec(function(err) { multi.exec(function(err, res) {
callback(err); callback(err);
}); });
}; };
module.setRemove = function(key, value, callback) { module.setRemove = function(key, value, callback) {
redisClient.srem(key, value, callback); redisClient.srem(key, value, function(err, res) {
callback(err);
});
}; };
module.setsRemove = function(keys, value, callback) { module.setsRemove = function(keys, value, callback) {

@ -68,36 +68,28 @@ SocketPosts.reply = function(socket, data, callback) {
}; };
SocketPosts.upvote = function(socket, data, callback) { SocketPosts.upvote = function(socket, data, callback) {
if (!data || !data.pid) { favouriteCommand(socket, 'upvote', 'voted', 'notifications:upvoted_your_post_in', data, callback);
return callback(new Error('[[error:invalid-data]]'));
}
favouriteCommand('upvote', 'voted', socket, data, callback);
SocketPosts.sendNotificationToPostOwner(data.pid, socket.uid, 'notifications:upvoted_your_post_in');
}; };
SocketPosts.downvote = function(socket, data, callback) { SocketPosts.downvote = function(socket, data, callback) {
favouriteCommand('downvote', 'voted', socket, data, callback); favouriteCommand(socket, 'downvote', 'voted', '', data, callback);
}; };
SocketPosts.unvote = function(socket, data, callback) { SocketPosts.unvote = function(socket, data, callback) {
favouriteCommand('unvote', 'voted', socket, data, callback); favouriteCommand(socket, 'unvote', 'voted', '', data, callback);
}; };
SocketPosts.favourite = function(socket, data, callback) { SocketPosts.favourite = function(socket, data, callback) {
if (!data || !data.pid) { favouriteCommand(socket, 'favourite', 'favourited', 'notifications:favourited_your_post_in', data, callback);
return callback(new Error('[[error:invalid-data]]'));
}
favouriteCommand('favourite', 'favourited', socket, data, callback);
SocketPosts.sendNotificationToPostOwner(data.pid, socket.uid, 'notifications:favourited_your_post_in');
}; };
SocketPosts.unfavourite = function(socket, data, callback) { SocketPosts.unfavourite = function(socket, data, callback) {
favouriteCommand('unfavourite', 'favourited', socket, data, callback); favouriteCommand(socket, 'unfavourite', 'favourited', '', data, callback);
}; };
function favouriteCommand(command, eventName, socket, data, callback) { function favouriteCommand(socket, command, eventName, notification, data, callback) {
if(!data || !data.pid || !data.room_id) { if(!data || !data.pid || !data.room_id) {
return; return callback(new Error('[[error:invalid-data]]'));
} }
async.parallel({ async.parallel({
exists: function(next) { exists: function(next) {
@ -108,7 +100,7 @@ function favouriteCommand(command, eventName, socket, data, callback) {
} }
}, function(err, results) { }, function(err, results) {
if (err || !results.exists) { if (err || !results.exists) {
return callback(err); return callback(err || new Error('[[error:invalid-pid]]'));
} }
if (parseInt(results.deleted, 10) === 1) { if (parseInt(results.deleted, 10) === 1) {
@ -122,16 +114,20 @@ function favouriteCommand(command, eventName, socket, data, callback) {
socket.emit('posts.' + command, result); socket.emit('posts.' + command, result);
if(data.room_id && result && eventName) { if (result && eventName) {
websockets.in(data.room_id).emit('event:' + eventName, result); websockets.in(data.room_id).emit('event:' + eventName, result);
} }
if (notification) {
SocketPosts.sendNotificationToPostOwner(data.pid, socket.uid, notification);
}
callback(); callback();
}); });
}); });
} }
SocketPosts.sendNotificationToPostOwner = function(pid, fromuid, notification) { SocketPosts.sendNotificationToPostOwner = function(pid, fromuid, notification) {
if(!pid || !fromuid) { if(!pid || !fromuid || !notification) {
return; return;
} }
posts.getPostFields(pid, ['tid', 'uid', 'content'], function(err, postData) { posts.getPostFields(pid, ['tid', 'uid', 'content'], function(err, postData) {

Loading…
Cancel
Save