mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: apply auto-categorization logic
This commit is contained in:
@@ -144,6 +144,11 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
|
|||||||
options.cid = remoteCid || recipientCids.shift();
|
options.cid = remoteCid || recipientCids.shift();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Auto-categorization (takes place only if all other categorization efforts fail)
|
||||||
|
if (!options.cid) {
|
||||||
|
options.cid = await assignCategory(mainPost);
|
||||||
|
}
|
||||||
|
|
||||||
// mainPid ok to leave as-is
|
// mainPid ok to leave as-is
|
||||||
title = title || activitypub.helpers.generateTitle(utils.decodeHTMLEntities(content || sourceContent));
|
title = title || activitypub.helpers.generateTitle(utils.decodeHTMLEntities(content || sourceContent));
|
||||||
|
|
||||||
@@ -384,6 +389,29 @@ async function assertRelation(post) {
|
|||||||
return followers > 0 || uids.length;
|
return followers > 0 || uids.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function assignCategory(post) {
|
||||||
|
let cid = undefined;
|
||||||
|
const rules = await activitypub.rules.list();
|
||||||
|
const tags = await Notes._normalizeTags(post._activitypub.tag || []);
|
||||||
|
|
||||||
|
cid = rules.reduce((cid, { type, value, cid: target }) => {
|
||||||
|
if (!cid) {
|
||||||
|
switch (type) {
|
||||||
|
case 'hashtag': {
|
||||||
|
if (tags.includes(value)) {
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return cid;
|
||||||
|
}, cid);
|
||||||
|
|
||||||
|
return cid;
|
||||||
|
}
|
||||||
|
|
||||||
Notes.updateLocalRecipients = async (id, { to, cc }) => {
|
Notes.updateLocalRecipients = async (id, { to, cc }) => {
|
||||||
const recipients = new Set([...(to || []), ...(cc || [])]);
|
const recipients = new Set([...(to || []), ...(cc || [])]);
|
||||||
const uids = new Set();
|
const uids = new Set();
|
||||||
|
|||||||
Reference in New Issue
Block a user