Merge remote-tracking branch 'origin/develop' into activitypub

This commit is contained in:
Julian Lam
2024-01-02 11:58:25 -05:00
20 changed files with 120 additions and 69 deletions

View File

@@ -128,7 +128,7 @@ categoriesAPI.getTopics = async (caller, data) => {
let start = Math.max(0, parseInt(data.after || 0, 10));
if (data.direction === -1) {
if (parseInt(data.direction, 10) === -1) {
start -= infScrollTopicsPerPage;
}

View File

@@ -236,7 +236,6 @@ module.exports = function (Categories) {
const notification = await notifications.create({
type: 'new-topic-in-category',
nid: `new_topic:tid:${postData.topic.tid}:uid:${exceptUid}`,
subject: bodyShort,
bodyShort: bodyShort,
bodyLong: postData.content,
pid: postData.pid,

View File

@@ -30,7 +30,7 @@ module.exports = function (SocketTopics) {
parseInt(data.count, 10) || meta.config.postsPerPage || 20
));
if (data.direction === -1) {
if (parseInt(data.direction, 10) === -1) {
start -= infScrollPostsPerPage;
}

View File

@@ -49,7 +49,7 @@ module.exports = function (Topics) {
tids = await Topics.filterWatchedTids(tids, params.uid);
}
} else if (params.filter === 'watched') {
tids = await db.getSortedSetRevRange(`uid:${params.uid}:followed_tids`, 0, -1);
tids = await getWatchedTopics(params);
} else if (params.cids) {
tids = await getCidTids(params);
} else if (params.tags.length) {
@@ -63,6 +63,17 @@ module.exports = function (Topics) {
return tids;
}
async function getWatchedTopics(params) {
const sortSet = ['recent', 'old'].includes(params.sort) ? 'topics:recent' : `topics:${params.sort}`;
const method = params.sort === 'old' ? 'getSortedSetIntersect' : 'getSortedSetRevIntersect';
return await db[method]({
sets: [sortSet, `uid:${params.uid}:followed_tids`],
weights: [1, 0],
start: 0,
stop: meta.config.recentMaxTopics - 1,
});
}
async function getTagTids(params) {
const sets = [
params.sort === 'old' ?

View File

@@ -620,7 +620,6 @@ module.exports = function (Topics) {
const notification = await notifications.create({
type: 'new-topic-with-tag',
nid: `new_topic:tid:${postData.topic.tid}:uid:${exceptUid}`,
subject: bodyShort,
bodyShort: bodyShort,
bodyLong: postData.content,
pid: postData.pid,

View File

@@ -210,15 +210,13 @@ module.exports = function (Topics) {
}
async function getFollowedTids(params) {
let tids = await db.getSortedSetMembers(`uid:${params.uid}:followed_tids`);
const filterCids = params.cid && params.cid.map(cid => parseInt(cid, 10));
if (filterCids) {
const topicData = await Topics.getTopicsFields(tids, ['tid', 'cid']);
tids = topicData.filter(t => filterCids.includes(t.cid)).map(t => t.tid);
}
const scores = await db.sortedSetScores('topics:recent', tids);
const data = tids.map((tid, index) => ({ value: String(tid), score: scores[index] }));
return data.filter(item => item.score > params.cutoff);
const keys = params.cid ?
params.cid.map(cid => `cid:${cid}:tids:lastposttime`) :
'topics:recent';
const recentTopicData = await db.getSortedSetRevRangeByScoreWithScores(keys, 0, -1, '+inf', params.cutoff);
const isFollowed = await db.isSortedSetMembers(`uid:${params.uid}:followed_tids`, recentTopicData.map(t => t.tid));
return recentTopicData.filter((t, i) => isFollowed[i]);
}
async function filterTidsThatHaveBlockedPosts(params) {