mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01:00
fix: don't show deleted topics on unread
This commit is contained in:
@@ -120,24 +120,17 @@ module.exports = function (Topics) {
|
||||
recentTids: categoryTids,
|
||||
});
|
||||
|
||||
tids = await privileges.topics.filterTids('topics:read', tids, params.uid);
|
||||
const topicData = await Topics.getTopicsFields(tids, ['tid', 'cid', 'uid', 'postcount']);
|
||||
const topicCids = _.uniq(topicData.map(topic => topic.cid)).filter(Boolean);
|
||||
|
||||
const [categoryWatchState, readCids] = await Promise.all([
|
||||
categories.getWatchState(topicCids, params.uid),
|
||||
privileges.categories.filterCids('topics:read', topicCids, params.uid),
|
||||
]);
|
||||
|
||||
const filterCids = params.cid && params.cid.map(String);
|
||||
const readableCids = readCids.map(String);
|
||||
const categoryWatchState = await categories.getWatchState(topicCids, params.uid);
|
||||
const userCidState = _.zipObject(topicCids, categoryWatchState);
|
||||
|
||||
topicData.forEach(function (topic) {
|
||||
function cidMatch() {
|
||||
return (!filterCids || (filterCids.length && filterCids.includes(String(topic.cid)))) && readableCids.includes(String(topic.cid));
|
||||
}
|
||||
const filterCids = params.cid && params.cid.map(cid => parseInt(cid, 10));
|
||||
|
||||
if (topic && topic.cid && cidMatch() && !blockedUids.includes(topic.uid)) {
|
||||
topicData.forEach(function (topic) {
|
||||
if (topic && topic.cid && (!filterCids || filterCids.includes(topic.cid)) && !blockedUids.includes(topic.uid)) {
|
||||
if (isTopicsFollowed[topic.tid] || userCidState[topic.cid] === categories.watchStates.watching) {
|
||||
tidsByFilter[''].push(topic.tid);
|
||||
}
|
||||
|
||||
@@ -1461,6 +1461,14 @@ describe('Topic\'s', function () {
|
||||
},
|
||||
], done);
|
||||
});
|
||||
|
||||
it('should not return topic as unread if topic is deleted', async function () {
|
||||
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 unreadTids = await topics.getUnreadTids({ cid: 0, uid: uid });
|
||||
assert(!unreadTids.includes(result.topicData.tid));
|
||||
});
|
||||
});
|
||||
|
||||
describe('tags', function () {
|
||||
|
||||
Reference in New Issue
Block a user