Node.js based forum software built for the modern web
if the main and last post is purged, purge the topic as well
Barış Soner Uşaklı7a6b685aa0d9
diff --git a/src/socket.io/posts/tools.js b/src/socket.io/posts/tools.jsindex c1ad05b119..c075a96a8e 100644--- a/src/socket.io/posts/tools.js+++ b/src/socket.io/posts/tools.js@@ -138,39 +138,46 @@ module.exports = function (SocketPosts) {return callback(new Error('[[error:invalid-data]]'));}var postData;+ var topicData;+ var isMainAndLast = false;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]]'));+ return next(new Error('[[error:cant-purge-main-post]]'));}- if (results.isMain && results.isLast) {- return deleteTopicOf(data.pid, socket, next);- }- setImmediate(next);- },- function (next) {- posts.getPostField(data.pid, 'toPid', next);+ isMainAndLast = results.isMain && results.isLast;++ posts.getPostFields(data.pid, ['toPid', 'tid'], next);},- function (toPid, next) {- postData = { pid: data.pid, toPid: toPid };+ function (_postData, next) {+ postData = _postData;+ postData.pid = data.pid;posts.tools.purge(socket.uid, data.pid, next);},function (next) {websockets.in('topic_' + data.tid).emit('event:post_purged', postData);- topics.getTopicField(data.tid, 'title', next);+ topics.getTopicFields(data.tid, ['title', 'cid'], next);},- function (title, next) {+ function (_topicData, next) {+ topicData = _topicData;events.log({type: 'post-purge',uid: socket.uid,pid: data.pid,ip: socket.ip,- title: String(title),+ title: String(topicData.title),}, next);},+ function (next) {+ if (isMainAndLast) {+ socketTopics.doTopicAction('purge', 'event:topic_purged', socket, { tids: [postData.tid], cid: topicData.cid }, next);+ } else {+ setImmediate(next);+ }+ },], callback);};diff --git a/test/posts.js b/test/posts.jsindex 49a4783872..50441a58e1 100644--- a/test/posts.js+++ b/test/posts.js@@ -274,16 +274,16 @@ describe('Post\'s', function () {});});- it('should purge posts and delete topic', function (done) {+ it('should purge posts and purge topic', function (done) {createTopicWithReply(function (topicPostData, replyData) {socketPosts.purgePosts({ uid: voterUid }, { pids: [replyData.pid, topicPostData.postData.pid], tid: topicPostData.topicData.tid }, function (err) {assert.ifError(err);posts.exists('post:' + replyData.pid, function (err, exists) {assert.ifError(err);assert.equal(exists, false);- topics.getTopicField(topicPostData.topicData.tid, 'deleted', function (err, deleted) {+ topics.exists(topicPostData.topicData.tid, function (err, exists) {assert.ifError(err);- assert.equal(parseInt(deleted, 10), 1);+ assert(!exists);done();});});