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