Merge branch 'develop' into activitypub

This commit is contained in:
Barış Soner Uşaklı
2024-04-25 11:16:42 -04:00
270 changed files with 2429 additions and 1668 deletions

View File

@@ -45,7 +45,7 @@ module.exports = function (Topics) {
let tids = [];
if (params.term !== 'alltime') {
if (params.sort === 'posts') {
tids = await getTidsWithMostPostsInTerm(params.term);
tids = await getTidsWithMostPostsInTerm(params.cids, params.uid, params.term);
} else {
tids = await Topics.getLatestTidsFromSet('topics:tid', 0, -1, params.term);
}
@@ -84,8 +84,20 @@ module.exports = function (Topics) {
return 'topics:recent';
}
async function getTidsWithMostPostsInTerm(term) {
const pids = await db.getSortedSetRevRangeByScore('posts:pid', 0, -1, '+inf', Date.now() - Topics.getSinceFromTerm(term));
async function getTidsWithMostPostsInTerm(cids, uid, term) {
if (Array.isArray(cids)) {
cids = await privileges.categories.filterCids('topics:read', cids, uid);
} else {
cids = await categories.getCidsByPrivilege('categories:cid', uid, 'topics:read');
}
const pids = await db.getSortedSetRevRangeByScore(
cids.map(cid => `cid:${cid}:pids`),
0,
1000,
'+inf',
Date.now() - Topics.getSinceFromTerm(term)
);
const postObjs = await db.getObjectsFields(pids.map(pid => `post:${pid}`), ['tid']);
const tidToCount = {};
postObjs.forEach((post) => {
@@ -93,7 +105,8 @@ module.exports = function (Topics) {
tidToCount[post.tid] += 1;
});
return _.uniq(postObjs.map(post => String(post.tid))).sort((t1, t2) => tidToCount[t2] - tidToCount[t1]);
return _.uniq(postObjs.map(post => String(post.tid)))
.sort((t1, t2) => tidToCount[t2] - tidToCount[t1]);
}
async function getWatchedTopics(params) {