|
|
|
@ -15,10 +15,11 @@ var social = require('../../social');
|
|
|
|
|
module.exports = function (SocketPosts) {
|
|
|
|
|
|
|
|
|
|
SocketPosts.loadPostTools = function (socket, data, callback) {
|
|
|
|
|
if (!data) {
|
|
|
|
|
if (!data || !data.pid || !data.cid) {
|
|
|
|
|
return callback(new Error('[[error:invalid-data]]'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
posts: function (next) {
|
|
|
|
|
posts.getPostFields(data.pid, ['deleted', 'bookmarks', 'uid'], next);
|
|
|
|
@ -41,11 +42,9 @@ module.exports = function (SocketPosts) {
|
|
|
|
|
postSharing: function (next) {
|
|
|
|
|
social.getActivePostSharing(next);
|
|
|
|
|
}
|
|
|
|
|
}, function (err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function (results, next) {
|
|
|
|
|
results.posts.tools = results.tools.tools;
|
|
|
|
|
results.posts.deleted = parseInt(results.posts.deleted, 10) === 1;
|
|
|
|
|
results.posts.bookmarked = results.bookmarked;
|
|
|
|
@ -54,8 +53,9 @@ module.exports = function (SocketPosts) {
|
|
|
|
|
results.posts.display_delete_tools = results.canDelete.flag;
|
|
|
|
|
results.posts.display_moderator_tools = results.posts.display_edit_tools || results.posts.display_delete_tools;
|
|
|
|
|
results.posts.display_move_tools = results.isAdminOrMod;
|
|
|
|
|
callback(null, results);
|
|
|
|
|
});
|
|
|
|
|
next(null, results);
|
|
|
|
|
}
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SocketPosts.delete = function (socket, data, callback) {
|
|
|
|
@ -98,10 +98,11 @@ module.exports = function (SocketPosts) {
|
|
|
|
|
return callback(new Error('[[error:invalid-data]]'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
posts.tools.restore(socket.uid, data.pid, function (err, postData) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
posts.tools.restore(socket.uid, data.pid, next);
|
|
|
|
|
},
|
|
|
|
|
function (postData, next) {
|
|
|
|
|
|
|
|
|
|
websockets.in('topic_' + data.tid).emit('event:post_restored', postData);
|
|
|
|
|
|
|
|
|
@ -112,15 +113,16 @@ module.exports = function (SocketPosts) {
|
|
|
|
|
ip: socket.ip
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
callback();
|
|
|
|
|
});
|
|
|
|
|
setImmediate(next);
|
|
|
|
|
}
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SocketPosts.deletePosts = function (socket, data, callback) {
|
|
|
|
|
if (!data || !Array.isArray(data.pids)) {
|
|
|
|
|
return callback(new Error('[[error:invalid-data]]'));
|
|
|
|
|
}
|
|
|
|
|
async.each(data.pids, function (pid, next) {
|
|
|
|
|
async.eachSeries(data.pids, function (pid, next) {
|
|
|
|
|
SocketPosts.delete(socket, {pid: pid, tid: data.tid}, next);
|
|
|
|
|
}, callback);
|
|
|
|
|
};
|
|
|
|
@ -129,15 +131,29 @@ module.exports = function (SocketPosts) {
|
|
|
|
|
if (!data || !Array.isArray(data.pids)) {
|
|
|
|
|
return callback(new Error('[[error:invalid-data]]'));
|
|
|
|
|
}
|
|
|
|
|
async.each(data.pids, function (pid, next) {
|
|
|
|
|
async.eachSeries(data.pids, function (pid, next) {
|
|
|
|
|
SocketPosts.purge(socket, {pid: pid, tid: data.tid}, next);
|
|
|
|
|
}, callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SocketPosts.purge = function (socket, data, callback) {
|
|
|
|
|
function purgePost() {
|
|
|
|
|
if (!data || !parseInt(data.pid, 10)) {
|
|
|
|
|
return callback(new Error('[[error:invalid-data]]'));
|
|
|
|
|
}
|
|
|
|
|
var postData;
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
isMainAndLastPost(data.pid, next);
|
|
|
|
|
},
|
|
|
|
|
function (results, next) {
|
|
|
|
|
if (results.isMain && !results.isLast) {
|
|
|
|
|
return callback(new Error('[[error:cant-purge-main-post]]'));
|
|
|
|
|
}
|
|
|
|
|
if (results.isMain && results.isLast) {
|
|
|
|
|
deleteTopicOf(data.pid, socket, next);
|
|
|
|
|
}
|
|
|
|
|
setImmediate(next);
|
|
|
|
|
},
|
|
|
|
|
function (next) {
|
|
|
|
|
posts.getPostField(data.pid, 'toPid', next);
|
|
|
|
|
},
|
|
|
|
@ -159,36 +175,17 @@ module.exports = function (SocketPosts) {
|
|
|
|
|
}, next);
|
|
|
|
|
}
|
|
|
|
|
], callback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!data || !parseInt(data.pid, 10)) {
|
|
|
|
|
return callback(new Error('[[error:invalid-data]]'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isMainAndLastPost(data.pid, function (err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!results.isMain) {
|
|
|
|
|
return purgePost();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!results.isLast) {
|
|
|
|
|
return callback(new Error('[[error:cant-purge-main-post]]'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
deleteTopicOf(data.pid, socket, callback);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function deleteTopicOf(pid, socket, callback) {
|
|
|
|
|
posts.getTopicFields(pid, ['tid', 'cid'], function (err, topic) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
posts.getTopicFields(pid, ['tid', 'cid'], next);
|
|
|
|
|
},
|
|
|
|
|
function (topic, next) {
|
|
|
|
|
socketTopics.doTopicAction('delete', 'event:topic_deleted', socket, {tids: [topic.tid], cid: topic.cid}, next);
|
|
|
|
|
}
|
|
|
|
|
socketTopics.doTopicAction('delete', 'event:topic_deleted', socket, {tids: [topic.tid], cid: topic.cid}, callback);
|
|
|
|
|
});
|
|
|
|
|
], callback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isMainAndLastPost(pid, callback) {
|
|
|
|
|