|
|
@ -13,9 +13,13 @@ helpers.postCommand = function (socket, command, eventName, notification, data,
|
|
|
|
if (!socket.uid) {
|
|
|
|
if (!socket.uid) {
|
|
|
|
return callback(new Error('[[error:not-logged-in]]'));
|
|
|
|
return callback(new Error('[[error:not-logged-in]]'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!data || !data.pid || !data.room_id) {
|
|
|
|
if (!data || !data.pid || !data.room_id) {
|
|
|
|
return callback(new Error('[[error:invalid-data]]'));
|
|
|
|
return callback(new Error('[[error:invalid-data]]'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
|
|
|
|
function (next) {
|
|
|
|
async.parallel({
|
|
|
|
async.parallel({
|
|
|
|
exists: function (next) {
|
|
|
|
exists: function (next) {
|
|
|
|
posts.exists(data.pid, next);
|
|
|
|
posts.exists(data.pid, next);
|
|
|
@ -23,13 +27,15 @@ helpers.postCommand = function (socket, command, eventName, notification, data,
|
|
|
|
deleted: function (next) {
|
|
|
|
deleted: function (next) {
|
|
|
|
posts.getPostField(data.pid, 'deleted', next);
|
|
|
|
posts.getPostField(data.pid, 'deleted', next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, function (err, results) {
|
|
|
|
}, next);
|
|
|
|
if (err || !results.exists) {
|
|
|
|
},
|
|
|
|
return callback(err || new Error('[[error:invalid-pid]]'));
|
|
|
|
function (results, next) {
|
|
|
|
|
|
|
|
if (!results.exists) {
|
|
|
|
|
|
|
|
return next(new Error('[[error:invalid-pid]]'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (parseInt(results.deleted, 10) === 1) {
|
|
|
|
if (parseInt(results.deleted, 10) === 1) {
|
|
|
|
return callback(new Error('[[error:post-deleted]]'));
|
|
|
|
return next(new Error('[[error:post-deleted]]'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
@ -40,24 +46,22 @@ helpers.postCommand = function (socket, command, eventName, notification, data,
|
|
|
|
filter:post.bookmark
|
|
|
|
filter:post.bookmark
|
|
|
|
filter:post.unbookmark
|
|
|
|
filter:post.unbookmark
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
plugins.fireHook('filter:post.' + command, {data: data, uid: socket.uid}, function (err, filteredData) {
|
|
|
|
plugins.fireHook('filter:post.' + command, {data: data, uid: socket.uid}, next);
|
|
|
|
if (err) {
|
|
|
|
},
|
|
|
|
return callback(err);
|
|
|
|
function (filteredData, next) {
|
|
|
|
|
|
|
|
executeCommand(socket, command, eventName, notification, filteredData.data, next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
], callback);
|
|
|
|
executeCommand(socket, command, eventName, notification, filteredData.data, callback);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function executeCommand(socket, command, eventName, notification, data, callback) {
|
|
|
|
function executeCommand(socket, command, eventName, notification, data, callback) {
|
|
|
|
posts[command](data.pid, socket.uid, function (err, result) {
|
|
|
|
async.waterfall([
|
|
|
|
if (err) {
|
|
|
|
function (next) {
|
|
|
|
return callback(err);
|
|
|
|
posts[command](data.pid, socket.uid, next);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
function (result, next) {
|
|
|
|
if (result && eventName) {
|
|
|
|
if (result && eventName) {
|
|
|
|
socket.emit('posts.' + command, result);
|
|
|
|
websockets.in('uid_' + socket.uid).emit('posts.' + command, result);
|
|
|
|
websockets.in(data.room_id).emit('event:' + eventName, result);
|
|
|
|
websockets.in(data.room_id).emit('event:' + eventName, result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -66,6 +70,7 @@ function executeCommand(socket, command, eventName, notification, data, callback
|
|
|
|
} else if (result && command === 'unvote') {
|
|
|
|
} else if (result && command === 'unvote') {
|
|
|
|
socketHelpers.rescindUpvoteNotification(data.pid, socket.uid);
|
|
|
|
socketHelpers.rescindUpvoteNotification(data.pid, socket.uid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
callback();
|
|
|
|
next(null, result);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
], callback);
|
|
|
|
}
|
|
|
|
}
|