mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
feat: add filter:topics.unreadCutoff
This commit is contained in:
@@ -30,14 +30,12 @@ unreadController.get = async function (req, res, next) {
|
||||
const page = parseInt(req.query.page, 10) || 1;
|
||||
const start = Math.max(0, (page - 1) * userSettings.topicsPerPage);
|
||||
const stop = start + userSettings.topicsPerPage - 1;
|
||||
const cutoff = req.session.unreadCutoff ? req.session.unreadCutoff : topics.unreadCutoff();
|
||||
const data = await topics.getUnreadTopics({
|
||||
cid: cid,
|
||||
uid: req.uid,
|
||||
start: start,
|
||||
stop: stop,
|
||||
filter: filter,
|
||||
cutoff: cutoff,
|
||||
query: req.query,
|
||||
});
|
||||
|
||||
|
||||
@@ -46,8 +46,10 @@ module.exports = function (Topics) {
|
||||
return unreadTopics;
|
||||
};
|
||||
|
||||
Topics.unreadCutoff = function () {
|
||||
return Date.now() - (meta.config.unreadCutoff * 86400000);
|
||||
Topics.unreadCutoff = async function (uid) {
|
||||
const cutoff = Date.now() - (meta.config.unreadCutoff * 86400000);
|
||||
const data = await plugins.fireHook('filter:topics.unreadCutoff', { uid: uid, cutoff: cutoff });
|
||||
return data.cutoff;
|
||||
};
|
||||
|
||||
Topics.getUnreadTids = async function (params) {
|
||||
@@ -88,13 +90,13 @@ module.exports = function (Topics) {
|
||||
return { counts: counts, tids: [], tidsByFilter: tidsByFilter };
|
||||
}
|
||||
|
||||
const cutoff = params.cutoff || Topics.unreadCutoff();
|
||||
params.cutoff = await Topics.unreadCutoff(params.uid);
|
||||
|
||||
const [followedTids, ignoredTids, categoryTids, userScores, tids_unread] = await Promise.all([
|
||||
getFollowedTids(params),
|
||||
user.getIgnoredTids(params.uid, 0, -1),
|
||||
getCategoryTids(params),
|
||||
db.getSortedSetRevRangeByScoreWithScores('uid:' + params.uid + ':tids_read', 0, -1, '+inf', cutoff),
|
||||
db.getSortedSetRevRangeByScoreWithScores('uid:' + params.uid + ':tids_read', 0, -1, '+inf', params.cutoff),
|
||||
db.getSortedSetRevRangeWithScores('uid:' + params.uid + ':tids_unread', 0, -1),
|
||||
]);
|
||||
|
||||
@@ -169,19 +171,16 @@ module.exports = function (Topics) {
|
||||
if (params.filter === 'watched') {
|
||||
return [];
|
||||
}
|
||||
const cutoff = params.cutoff || Topics.unreadCutoff();
|
||||
const cids = params.cid || await user.getWatchedCategories(params.uid);
|
||||
const keys = cids.map(cid => 'cid:' + cid + ':tids:lastposttime');
|
||||
return await db.getSortedSetRevRangeByScoreWithScores(keys, 0, -1, '+inf', cutoff);
|
||||
return await db.getSortedSetRevRangeByScoreWithScores(keys, 0, -1, '+inf', params.cutoff);
|
||||
}
|
||||
|
||||
async function getFollowedTids(params) {
|
||||
const tids = await db.getSortedSetRevRange('uid:' + params.uid + ':followed_tids', 0, -1);
|
||||
const scores = await db.sortedSetScores('topics:recent', tids);
|
||||
const cutoff = params.cutoff || Topics.unreadCutoff();
|
||||
|
||||
const data = tids.map((tid, index) => ({ value: tid, score: scores[index] }));
|
||||
return data.filter(item => item.score > cutoff);
|
||||
return data.filter(item => item.score > params.cutoff);
|
||||
}
|
||||
|
||||
async function filterTidsThatHaveBlockedPosts(params) {
|
||||
@@ -285,7 +284,8 @@ module.exports = function (Topics) {
|
||||
};
|
||||
|
||||
Topics.markAllRead = async function (uid) {
|
||||
const tids = await db.getSortedSetRevRangeByScore('topics:recent', 0, -1, '+inf', Topics.unreadCutoff());
|
||||
const cutoff = await Topics.unreadCutoff(uid);
|
||||
const tids = await db.getSortedSetRevRangeByScore('topics:recent', 0, -1, '+inf', cutoff);
|
||||
Topics.markTopicNotificationsRead(tids, uid);
|
||||
await Topics.markAsRead(tids, uid);
|
||||
await db.delete('uid:' + uid + ':tids_unread');
|
||||
@@ -316,7 +316,7 @@ module.exports = function (Topics) {
|
||||
user.blocks.list(uid),
|
||||
]);
|
||||
|
||||
const cutoff = Topics.unreadCutoff();
|
||||
const cutoff = await Topics.unreadCutoff(uid);
|
||||
const result = tids.map(function (tid, index) {
|
||||
const read = !tids_unread[index] &&
|
||||
(topicScores[index] < cutoff ||
|
||||
|
||||
Reference in New Issue
Block a user