Skip to content
Permalink
Browse files

fix: don't show deleted topics on unread

  • Loading branch information...
barisusakli committed Oct 9, 2019
1 parent 6b3eb01 commit 661a0f506828ec4ef03e3db8508484d1df6977a6
Showing with 13 additions and 12 deletions.
  1. +5 −12 src/topics/unread.js
  2. +8 −0 test/topics.js
@@ -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 () {

0 comments on commit 661a0f5

Please sign in to comment.
You can’t perform that action at this time.