if the main and last post is purged, purge the topic as well

v1.18.x
Barış Soner Uşaklı 8 years ago
parent 870bb87b08
commit 7a6b685aa0

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

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

Loading…
Cancel
Save