Skip to content

Node.js based forum software built for the modern web

fix(activitypub): queue crossposts when category is pre-resolved

Julian Lam6d6038644370
diff --git a/public/language/en-GB/post-queue.json b/public/language/en-GB/post-queue.json
index 13fce2e9ac..7212aad374 100644
--- a/public/language/en-GB/post-queue.json
+++ b/public/language/en-GB/post-queue.json
@@ -20,6 +20,7 @@
"title-editable": "Click on title to edit",
"reply": "Reply",
"topic": "Topic",
+ "crosspost": "Crosspost",
"accept": "Accept",
"reject": "Reject",
"remove": "Remove",
diff --git a/src/activitypub/notes.js b/src/activitypub/notes.js
index 668a30b61f..437ca506ee 100644
--- a/src/activitypub/notes.js
+++ b/src/activitypub/notes.js
@@ -196,8 +196,10 @@ Notes.assert = async (uid, input, options = { skipChecks: false, queue: false })
crosspostCid = cid;
if (!options.cid) {
options.cid = crosspostCid;
- options.queue = filter;
- crosspostCid = false;
+ }
+ // Always respect the filter flag for queuing crossposts
+ if (crosspostCid) {
+ options.queue = options.queue || filter;
}
// mainPid ok to leave as-is
@@ -273,7 +275,7 @@ Notes.assert = async (uid, input, options = { skipChecks: false, queue: false })
return null;
}
- await posts.addToQueue({
+ const queueData = {
uid: authorId,
cid: options.cid || cid,
pid: mainPid,
@@ -283,7 +285,12 @@ Notes.assert = async (uid, input, options = { skipChecks: false, queue: false })
sourceContent: mainPost.sourceContent,
generatedTitle,
_activitypub: mainPost._activitypub,
- });
+ };
+ if (options.queue && crosspostCid) {
+ queueData.crosspostCid = crosspostCid;
+ }
+
+ await posts.addToQueue(queueData);
// Drop the rest of the chain — replies without OP don't make sense
return { tid: null, queued: 1 };
diff --git a/src/api/posts.js b/src/api/posts.js
index 1b323ebbf4..4b19d62a8c 100644
--- a/src/api/posts.js
+++ b/src/api/posts.js
@@ -650,6 +650,9 @@ async function logQueueEvent(caller, result, type) {
if (result.type === 'topic') {
eventData.cid = result.data.cid;
eventData.title = result.data.title;
+ } else if (result.type === 'crosspost') {
+ eventData.tid = result.data.tid;
+ eventData.crosspostCid = result.data.crosspostCid;
} else {
eventData.tid = result.data.tid;
}
diff --git a/src/controllers/mods.js b/src/controllers/mods.js
index 25ec70688f..828909d890 100644
--- a/src/controllers/mods.js
+++ b/src/controllers/mods.js
@@ -248,7 +248,7 @@ modsController.postQueue = async function (req, res, next) {
postData = postData.slice(start, stop + 1);
const crumbs = [{ text: '[[pages:post-queue]]', url: id ? '/post-queue' : undefined }];
if (id && postData.length) {
- const text = postData[0].data.tid ? '[[post-queue:reply]]' : '[[post-queue:topic]]';
+ const text = postData[0].data.tid ? '[[post-queue:reply]]' : (postData[0].data.crosspostCid ? '[[post-queue:crosspost]]' : '[[post-queue:topic]]');
crumbs.push({ text: text });
}
res.render('post-queue', {
diff --git a/src/posts/queue.js b/src/posts/queue.js
index 106b7cddc7..7290b0a6bb 100644
--- a/src/posts/queue.js
+++ b/src/posts/queue.js
@@ -79,7 +79,9 @@ module.exports = function (Posts) {
return;
}
postData.topic = { cid: 0 };
- if (postData.data.cid) {
+ if (postData.data.crosspostCid) {
+ postData.topic = { cid: parseInt(postData.data.crosspostCid, 10) };
+ } else if (postData.data.cid) {
postData.topic = { cid: parseInt(postData.data.cid, 10) };
} else if (postData.data.tid) {
postData.topic = await topics.getTopicFields(postData.data.tid, ['title', 'cid', 'lastposttime']);
@@ -160,6 +162,8 @@ module.exports = function (Posts) {
function getType(data) {
if (data.hasOwnProperty('tid')) {
return 'reply';
+ } else if (data.hasOwnProperty('crosspostCid')) {
+ return 'crosspost';
} else if (data.hasOwnProperty('cid')) {
return 'topic';
}
@@ -267,6 +271,8 @@ module.exports = function (Posts) {
return data.cid;
} else if (type === 'reply') {
return await topics.getTopicField(data.tid, 'cid');
+ } else if (type === 'crosspost') {
+ return data.crosspostCid;
}
return null;
}
@@ -276,9 +282,12 @@ module.exports = function (Posts) {
const typeToPrivilege = {
topic: 'topics:create',
reply: 'topics:reply',
+ crosspost: 'topics:crosspost',
};
- topics.checkContent(data.sourceContent || data.content);
+ if (type !== 'crosspost') {
+ topics.checkContent(data.sourceContent || data.content);
+ }
if (type === 'topic') {
topics.checkTitle(data.title);
if (data.tags) {
@@ -328,6 +337,9 @@ module.exports = function (Posts) {
const result = await createReply(data.data);
data.pid = result.pid;
data.tid = result.tid;
+ } else if (data.type === 'crosspost') {
+ const result = await createCrosspost(data.data);
+ data.tid = result.tid;
}
await removeFromQueue(id);
plugins.hooks.fire('action:post-queue:submitFromQueue', { data: data });
@@ -354,6 +366,11 @@ module.exports = function (Posts) {
return result;
}
+ async function createCrosspost(data) {
+ const result = await topics.crossposts.add(data.tid, data.crosspostCid, data.uid || 0);
+ return { tid: data.tid };
+ }
+
async function createReply(data) {
const postData = await topics.reply(data);
const result = {
diff --git a/src/views/post-queue.tpl b/src/views/post-queue.tpl
index 12c3b56df3..2da111c611 100644
--- a/src/views/post-queue.tpl
+++ b/src/views/post-queue.tpl
@@ -70,7 +70,7 @@
<input id="{./id}" type="checkbox" class="form-check-input" autocomplete="off" />
{{{ end }}}
<label for="{./id}" class="small stretched-link">
- {{{ if posts.data.tid }}}[[post-queue:reply]]{{{ else }}}[[post-queue:topic]]{{{ end }}}
+ {{{ if posts.data.tid }}}[[post-queue:reply]]{{{ else if posts.data.crosspostCid }}}[[post-queue:crosspost]]{{{ else }}}[[post-queue:topic]]{{{ end }}}
</label>
</li>
<li class="card-body d-flex flex-column gap-1 border-bottom">
diff --git a/test/topics/crossposts.js b/test/topics/crossposts.js
index 104c16ce4c..b340200380 100644
--- a/test/topics/crossposts.js
+++ b/test/topics/crossposts.js
@@ -488,7 +488,7 @@ describe('Crossposting (& related logic)', () => {
content: utils.generateUUID(),
});
tid = topicData.tid;
- pid = topicData.mainPid,
+ pid = topicData.mainPid;
// Add some remote followers
await Promise.all([cid1, cid2].map(async (cid) => {