Skip to content

Node.js based forum software built for the modern web

fix(activitypub): separate crosspost queue from add to fix filter regression

Julian Lamd05e4ec1dd6b
diff --git a/src/activitypub/notes.js b/src/activitypub/notes.js
index 437ca506ee..2ed3479f0a 100644
--- a/src/activitypub/notes.js
+++ b/src/activitypub/notes.js
@@ -140,6 +140,7 @@ Notes.assert = async (uid, input, options = { skipChecks: false, queue: false })
const cid = hasTid ? await topics.getTopicField(tid, 'cid') : options.cid || -1;
let crosspostCid = false;
+ let filter = false;
if (options.cid && cid === -1) {
// Move topic if currently uncategorized
@@ -192,15 +193,13 @@ Notes.assert = async (uid, input, options = { skipChecks: false, queue: false })
}
// Auto-categorization (takes place only if all other categorization efforts fail)
- const { cid, filter } = await assignCategory(mainPost);
+ const { cid, filter: ruleFilter } = await assignCategory(mainPost);
+ filter = ruleFilter;
crosspostCid = cid;
if (!options.cid) {
options.cid = crosspostCid;
}
- // Always respect the filter flag for queuing crossposts
- if (crosspostCid) {
- options.queue = options.queue || filter;
- }
+ // filter is used below to decide whether to queue or add the crosspost
// mainPid ok to leave as-is
if (!title) {
@@ -269,7 +268,7 @@ Notes.assert = async (uid, input, options = { skipChecks: false, queue: false })
}
if ((mainResult.severity === 3 || options.queue) && meta.config.postQueue) {
- activitypub.helpers.log(`[activitypub/notes.assert] Queuing main post (${mainPid}) due to blocklist severity 3${options.queue ? ' or categorization rule' : ''}`);
+ activitypub.helpers.log(`[activitypub/notes.assert] Queuing main post (${mainPid}) due to blocklist severity 3${options.queue ? ' or explicit queue option' : ''}`);
if (utils.isNumber(mainPid) || (await posts.exists([mainPid]))[0]) {
activitypub.helpers.log(`[activitypub/notes.assert] Rejecting to-be-queued main post (${mainPid}): pid is local or already exists`);
return null;
@@ -397,7 +396,11 @@ Notes.assert = async (uid, input, options = { skipChecks: false, queue: false })
await Notes.syncUserInboxes(tid, uid);
if (crosspostCid) {
- await topics.crossposts.add(tid, crosspostCid, 0);
+ if (filter) {
+ await topics.crossposts.queue(tid, crosspostCid, 0);
+ } else {
+ await topics.crossposts.add(tid, crosspostCid, 0);
+ }
}
if (!hasTid && uid && options.cid) {
diff --git a/src/topics/crossposts.js b/src/topics/crossposts.js
index 3afc4c3137..1fe99a7edb 100644
--- a/src/topics/crossposts.js
+++ b/src/topics/crossposts.js
@@ -4,6 +4,7 @@ const winston = require('winston');
const _ = require('lodash');
const db = require('../database');
const topics = require('.');
+const meta = require('../meta');
const user = require('../user');
const categories = require('../categories');
const posts = require('../posts');
@@ -116,6 +117,17 @@ Crossposts.add = async function (tid, cid, uid) {
return [...crossposts, { id: crosspostId, uid, tid, cid, timestamp: now }];
};
+Crossposts.queue = async function (tid, cid, uid) {
+ if (!meta.config.postQueue) {
+ return;
+ }
+ await posts.addToQueue({
+ uid: uid || 0,
+ tid,
+ crosspostCid: cid,
+ });
+};
+
Crossposts.remove = async function (tid, cid, uid) {
let crossposts = await Crossposts.get(tid);
const [isPrivileged, isMod] = await Promise.all([