Skip to content

Commit

Permalink
fix: don't show deleted topics on unread
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Oct 9, 2019
1 parent 6b3eb01 commit 661a0f5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/topics/unread.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -120,24 +120,17 @@ module.exports = function (Topics) {
recentTids: categoryTids, recentTids: categoryTids,
}); });


tids = await privileges.topics.filterTids('topics:read', tids, params.uid);
const topicData = await Topics.getTopicsFields(tids, ['tid', 'cid', 'uid', 'postcount']); const topicData = await Topics.getTopicsFields(tids, ['tid', 'cid', 'uid', 'postcount']);
const topicCids = _.uniq(topicData.map(topic => topic.cid)).filter(Boolean); const topicCids = _.uniq(topicData.map(topic => topic.cid)).filter(Boolean);


const [categoryWatchState, readCids] = await Promise.all([ const categoryWatchState = await categories.getWatchState(topicCids, params.uid);
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 userCidState = _.zipObject(topicCids, categoryWatchState); const userCidState = _.zipObject(topicCids, categoryWatchState);


topicData.forEach(function (topic) { const filterCids = params.cid && params.cid.map(cid => parseInt(cid, 10));
function cidMatch() {
return (!filterCids || (filterCids.length && filterCids.includes(String(topic.cid)))) && readableCids.includes(String(topic.cid));
}


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) { if (isTopicsFollowed[topic.tid] || userCidState[topic.cid] === categories.watchStates.watching) {
tidsByFilter[''].push(topic.tid); tidsByFilter[''].push(topic.tid);
} }
Expand Down
8 changes: 8 additions & 0 deletions test/topics.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1461,6 +1461,14 @@ describe('Topic\'s', function () {
}, },
], done); ], 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 () { describe('tags', function () {
Expand Down

0 comments on commit 661a0f5

Please sign in to comment.