mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-15 12:02:54 +01:00
fix: update auto-categorization rules to also handle already-categorized topics via crosspost
This commit is contained in:
@@ -104,6 +104,7 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
|
||||
const hasTid = !!tid;
|
||||
|
||||
const cid = hasTid ? await topics.getTopicField(tid, 'cid') : options.cid || -1;
|
||||
let crosspostCid = false;
|
||||
|
||||
if (options.cid && cid === -1) {
|
||||
// Move topic if currently uncategorized
|
||||
@@ -155,8 +156,10 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
|
||||
}
|
||||
|
||||
// Auto-categorization (takes place only if all other categorization efforts fail)
|
||||
crosspostCid = await assignCategory(mainPost);
|
||||
if (!options.cid) {
|
||||
options.cid = await assignCategory(mainPost);
|
||||
options.cid = crosspostCid;
|
||||
crosspostCid = false;
|
||||
}
|
||||
|
||||
// mainPid ok to leave as-is
|
||||
@@ -265,6 +268,10 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
|
||||
|
||||
await Notes.syncUserInboxes(tid, uid);
|
||||
|
||||
if (crosspostCid) {
|
||||
await topics.crossposts.add(tid, crosspostCid, 0);
|
||||
}
|
||||
|
||||
if (!hasTid && uid && options.cid) {
|
||||
// New topic, have category announce it
|
||||
await activitypub.out.announce.topic(tid);
|
||||
|
||||
@@ -76,7 +76,7 @@ Crossposts.add = async function (tid, cid, uid) {
|
||||
db.sortedSetAdd(`cid:${cid}:pids`, pidTimestamps, pids),
|
||||
db.setObject(`crosspost:${crosspostId}`, { uid, tid, cid, timestamp: now }),
|
||||
db.sortedSetAdd(`tid:${tid}:crossposts`, now, crosspostId),
|
||||
db.sortedSetAdd(`uid:${uid}:crossposts`, now, crosspostId),
|
||||
uid > 0 ? db.sortedSetAdd(`uid:${uid}:crossposts`, now, crosspostId) : false,
|
||||
]);
|
||||
await categories.onTopicsMoved([cid]);
|
||||
} else {
|
||||
@@ -121,7 +121,7 @@ Crossposts.remove = async function (tid, cid, uid) {
|
||||
db.sortedSetRemoveBulk(bulkRemove),
|
||||
db.delete(`crosspost:${crosspostId}`),
|
||||
db.sortedSetRemove(`tid:${tid}:crossposts`, crosspostId),
|
||||
db.sortedSetRemove(`uid:${uid}:crossposts`, crosspostId),
|
||||
uid > 0 ? db.sortedSetRemove(`uid:${uid}:crossposts`, crosspostId) : false,
|
||||
]);
|
||||
await categories.onTopicsMoved([cid]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user