mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-24 01:10:31 +01:00
feat: syncUserInboxes to take into account remote topic tags, closes #13074
This commit is contained in:
@@ -414,9 +414,9 @@ Notes.getParentChain = async (uid, input) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Notes.syncUserInboxes = async function (tid, uid) {
|
Notes.syncUserInboxes = async function (tid, uid) {
|
||||||
const [pids, { cid, mainPid }] = await Promise.all([
|
const [pids, { cid, mainPid, tags }] = await Promise.all([
|
||||||
db.getSortedSetMembers(`tid:${tid}:posts`),
|
db.getSortedSetMembers(`tid:${tid}:posts`),
|
||||||
topics.getTopicFields(tid, ['tid', 'cid', 'mainPid']),
|
topics.getTopicFields(tid, ['tid', 'cid', 'mainPid', 'tags']),
|
||||||
]);
|
]);
|
||||||
pids.unshift(mainPid);
|
pids.unshift(mainPid);
|
||||||
|
|
||||||
@@ -426,6 +426,12 @@ Notes.syncUserInboxes = async function (tid, uid) {
|
|||||||
uids.add(parseInt(uid, 10));
|
uids.add(parseInt(uid, 10));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tag followers
|
||||||
|
const tagsFollowers = await topics.getTagsFollowers(tags.map(tag => tag.value));
|
||||||
|
new Set(tagsFollowers.flat()).forEach((uid) => {
|
||||||
|
uids.add(uid);
|
||||||
|
});
|
||||||
|
|
||||||
const keys = Array.from(uids).map(uid => `uid:${uid}:inbox`);
|
const keys = Array.from(uids).map(uid => `uid:${uid}:inbox`);
|
||||||
const score = await db.sortedSetScore(`cid:${cid}:tids`, tid);
|
const score = await db.sortedSetScore(`cid:${cid}:tids`, tid);
|
||||||
|
|
||||||
|
|||||||
@@ -564,6 +564,10 @@ module.exports = function (Topics) {
|
|||||||
return await db.getSortedSetRange(`tag:${tag}:followers`, start, stop);
|
return await db.getSortedSetRange(`tag:${tag}:followers`, start, stop);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Topics.getTagsFollowers = async function (tags) {
|
||||||
|
return await db.getSortedSetsMembers(tags.map(tag => `tag:${tag}:followers`));
|
||||||
|
};
|
||||||
|
|
||||||
Topics.followTag = async (tag, uid) => {
|
Topics.followTag = async (tag, uid) => {
|
||||||
if (!(parseInt(uid, 10) > 0)) {
|
if (!(parseInt(uid, 10) > 0)) {
|
||||||
throw new Error('[[error:not-logged-in]]');
|
throw new Error('[[error:not-logged-in]]');
|
||||||
|
|||||||
Reference in New Issue
Block a user