diff --git a/src/topics/create.js b/src/topics/create.js index d2b709333c..ef94fdaf42 100644 --- a/src/topics/create.js +++ b/src/topics/create.js @@ -167,14 +167,15 @@ module.exports = function (Topics) { topicData.index = 0; postData.index = 0; - if (topicData.scheduled) { - await Topics.delete(tid); + if (data.deleted || topicData.scheduled) { + await Topics.delete(tid, uid); + topicData.deleted = true; } analytics.increment(['topics', `topics:byCid:${topicData.cid}`]); plugins.hooks.fire('action:topic.post', { topic: topicData, post: postData, data: data }); - if (!topicData.scheduled) { + if (!topicData.scheduled && !topicData.deleted) { setImmediate(async () => { try { if (utils.isNumber(uid)) { diff --git a/test/topics.js b/test/topics.js index f67e0fc40e..479167717a 100644 --- a/test/topics.js +++ b/test/topics.js @@ -1420,8 +1420,14 @@ describe('Topic\'s', () => { it('should not return topic as unread if topic is deleted', async () => { const uid = await User.create({ username: 'regularJoe' }); - const result = await topics.post({ uid: adminUid, title: 'deleted unread', content: 'not unread', cid: categoryObj.cid }); - await topics.delete(result.topicData.tid, adminUid); + const result = await topics.post({ + uid: adminUid, + title: 'deleted unread', + content: 'not unread', + cid: categoryObj.cid, + deleted: 1, + }); + const unreadTids = await topics.getUnreadTids({ cid: 0, uid: uid }); await sleep(2000);