mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 18:46:01 +01:00
if the main and last post is purged, purge the topic as well
This commit is contained in:
@@ -138,39 +138,46 @@ module.exports = function (SocketPosts) {
|
|||||||
return callback(new Error('[[error:invalid-data]]'));
|
return callback(new Error('[[error:invalid-data]]'));
|
||||||
}
|
}
|
||||||
var postData;
|
var postData;
|
||||||
|
var topicData;
|
||||||
|
var isMainAndLast = false;
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
isMainAndLastPost(data.pid, next);
|
isMainAndLastPost(data.pid, next);
|
||||||
},
|
},
|
||||||
function (results, next) {
|
function (results, next) {
|
||||||
if (results.isMain && !results.isLast) {
|
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) {
|
isMainAndLast = results.isMain && results.isLast;
|
||||||
return deleteTopicOf(data.pid, socket, next);
|
|
||||||
}
|
posts.getPostFields(data.pid, ['toPid', 'tid'], next);
|
||||||
setImmediate(next);
|
|
||||||
},
|
},
|
||||||
function (next) {
|
function (_postData, next) {
|
||||||
posts.getPostField(data.pid, 'toPid', next);
|
postData = _postData;
|
||||||
},
|
postData.pid = data.pid;
|
||||||
function (toPid, next) {
|
|
||||||
postData = { pid: data.pid, toPid: toPid };
|
|
||||||
posts.tools.purge(socket.uid, data.pid, next);
|
posts.tools.purge(socket.uid, data.pid, next);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
websockets.in('topic_' + data.tid).emit('event:post_purged', postData);
|
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({
|
events.log({
|
||||||
type: 'post-purge',
|
type: 'post-purge',
|
||||||
uid: socket.uid,
|
uid: socket.uid,
|
||||||
pid: data.pid,
|
pid: data.pid,
|
||||||
ip: socket.ip,
|
ip: socket.ip,
|
||||||
title: String(title),
|
title: String(topicData.title),
|
||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
|
function (next) {
|
||||||
|
if (isMainAndLast) {
|
||||||
|
socketTopics.doTopicAction('purge', 'event:topic_purged', socket, { tids: [postData.tid], cid: topicData.cid }, next);
|
||||||
|
} else {
|
||||||
|
setImmediate(next);
|
||||||
|
}
|
||||||
|
},
|
||||||
], callback);
|
], 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) {
|
createTopicWithReply(function (topicPostData, replyData) {
|
||||||
socketPosts.purgePosts({ uid: voterUid }, { pids: [replyData.pid, topicPostData.postData.pid], tid: topicPostData.topicData.tid }, function (err) {
|
socketPosts.purgePosts({ uid: voterUid }, { pids: [replyData.pid, topicPostData.postData.pid], tid: topicPostData.topicData.tid }, function (err) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
posts.exists('post:' + replyData.pid, function (err, exists) {
|
posts.exists('post:' + replyData.pid, function (err, exists) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(exists, false);
|
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.ifError(err);
|
||||||
assert.equal(parseInt(deleted, 10), 1);
|
assert(!exists);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user