From b192605450d97bdd3dd7bf65c47efa099300211a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 1 Oct 2019 22:14:50 -0400 Subject: [PATCH] feat: add new hook to get custom category tids for unread --- src/controllers/unread.js | 1 + src/topics/unread.js | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/controllers/unread.js b/src/controllers/unread.js index 63a7fcb12c..57ca4eef61 100644 --- a/src/controllers/unread.js +++ b/src/controllers/unread.js @@ -38,6 +38,7 @@ unreadController.get = async function (req, res, next) { stop: stop, filter: filter, cutoff: cutoff, + query: req.query, }); data.title = meta.config.homePageTitle || '[[pages:home]]'; diff --git a/src/topics/unread.js b/src/topics/unread.js index 24f74363a3..231627bbf9 100644 --- a/src/topics/unread.js +++ b/src/topics/unread.js @@ -90,10 +90,10 @@ module.exports = function (Topics) { const cutoff = params.cutoff || Topics.unreadCutoff(); - const [followedTids, ignoredTids, recentTids, userScores, tids_unread] = await Promise.all([ + const [followedTids, ignoredTids, categoryTids, userScores, tids_unread] = await Promise.all([ getFollowedTids(params), user.getIgnoredTids(params.uid, 0, -1), - getRecentTids(params), + getCategoryTids(params), db.getSortedSetRevRangeByScoreWithScores('uid:' + params.uid + ':tids_read', 0, -1, '+inf', cutoff), db.getSortedSetRevRangeWithScores('uid:' + params.uid + ':tids_unread', 0, -1), ]); @@ -101,7 +101,7 @@ module.exports = function (Topics) { const userReadTime = _.mapValues(_.keyBy(userScores, 'value'), 'score'); const isTopicsFollowed = _.mapValues(_.keyBy(followedTids, 'value'), 'score'); - const unreadTopics = _.unionWith(recentTids, followedTids.concat(tids_unread), (a, b) => a.value === b.value) + const unreadTopics = _.unionWith(categoryTids, followedTids.concat(tids_unread), (a, b) => a.value === b.value) .filter(t => !ignoredTids.includes(t.value) && (!userReadTime[t.value] || t.score > userReadTime[t.value])) .sort((a, b) => b.score - a.score); @@ -117,7 +117,7 @@ module.exports = function (Topics) { uid: params.uid, tids: tids, blockedUids: blockedUids, - recentTids: recentTids, + recentTids: categoryTids, }); const topicData = await Topics.getTopicsFields(tids, ['tid', 'cid', 'uid', 'postcount']); @@ -168,7 +168,11 @@ module.exports = function (Topics) { }; } - async function getRecentTids(params) { + async function getCategoryTids(params) { + if (plugins.hasListeners('filter:topics.unread.getCategoryTids')) { + const result = await plugins.fireHook('filter:topics.unread.getCategoryTids', { params: params, tids: [] }); + return result.tids; + } if (params.filter === 'watched') { return []; }