Skip to content

Node.js based forum software built for the modern web

fix: proper queuing of incoming ap content when it is already in a remote category

Julian Lam5dca2408d7c1
diff --git a/public/language/en-GB/notifications.json b/public/language/en-GB/notifications.json
index 73832464dc..c0cc9b3d47 100644
--- a/public/language/en-GB/notifications.json
+++ b/public/language/en-GB/notifications.json
@@ -73,6 +73,7 @@
"flag-assigned-to-you": "<strong>Flag %1</strong> has been assigned to you",
"post-awaiting-review": "Post awaiting review",
"topic-awaiting-review": "Topic awaiting review",
+ "crosspost-awaiting-review": "Crosspost awaiting review",
"profile-exported": "<strong>%1</strong> profile exported, click to download",
"posts-exported": "<strong>%1</strong> posts exported, click to download",
"uploads-exported": "<strong>%1</strong> uploads exported, click to download",
diff --git a/src/activitypub/notes.js b/src/activitypub/notes.js
index 6dd65843f4..a2afbda2a8 100644
--- a/src/activitypub/notes.js
+++ b/src/activitypub/notes.js
@@ -267,7 +267,7 @@ Notes.assert = async (uid, input, options = { skipChecks: false, queue: false })
return null;
}
- if ((mainResult.severity === 3 || options.queue) && meta.config.postQueue) {
+ if ((mainResult.severity === 3 || (utils.isNumber(options.cid) && options.queue)) && meta.config.postQueue) {
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`);
@@ -285,9 +285,6 @@ Notes.assert = async (uid, input, options = { skipChecks: false, queue: false })
generatedTitle,
_activitypub: mainPost._activitypub,
};
- if (options.queue && crosspostCid) {
- queueData.crosspostCid = crosspostCid;
- }
await posts.addToQueue(queueData);
diff --git a/src/posts/queue.js b/src/posts/queue.js
index b1eea062f4..481084a36a 100644
--- a/src/posts/queue.js
+++ b/src/posts/queue.js
@@ -84,12 +84,20 @@ module.exports = function (Posts) {
const topicData = await topics.getTopicFields(postData.data.tid, ['title', 'timestamp', 'uid', 'mainPid', 'cid', 'lastposttime']);
postData.topic = topicData;
postData.data.title = topicData.title || '';
+ postData.data.timestamp = topicData.timestamp;
+ postData.data.timestampISO = topicData.timestampISO;
if (topicData.mainPid) {
- const firstPost = await Posts.getPostFields(topicData.mainPid, ['content']);
+ const firstPost = await Posts.getPostFields(topicData.mainPid, ['content', 'sourceContent']);
if (firstPost) {
- postData.data.content = firstPost.content || '';
+ postData.data.content = firstPost.content || firstPost.sourceContent || '';
}
}
+
+ // uid queued is 0 because system user queued it, so user metadata is retrieved here instead
+ const userData = await user.getUserFields(topicData.uid, [
+ 'username', 'userslug', 'picture', 'icon:bgColor', 'joindate', 'postcount', 'reputation',
+ ]);
+ postData.user = userData;
} else {
postData.topic = { cid: parseInt(postData.data.crosspostCid, 10) };
}
@@ -104,7 +112,7 @@ module.exports = function (Posts) {
);
}
- postData.category = await categories.getCategoryData(postData.topic.cid);
+ postData.category = await categories.getCategoryData(postData.data.crosspostCid || postData.topic.cid);
const result = await plugins.hooks.fire('filter:parse.post', { postData: postData.data });
postData.data.content = result.postData.content;
}
@@ -400,7 +408,7 @@ module.exports = function (Posts) {
}
async function createCrosspost(data) {
- await topics.crossposts.add(data.tid, data.crosspostCid, data.uid || 0);
+ await topics.crossposts.add(data.tid, data.crosspostCid, 'system');
return { tid: data.tid };
}
diff --git a/src/views/post-queue.tpl b/src/views/post-queue.tpl
index a5fcd2bb26..060ffd730d 100644
--- a/src/views/post-queue.tpl
+++ b/src/views/post-queue.tpl
@@ -70,9 +70,12 @@
<input id="{./id}" type="checkbox" class="form-check-input" autocomplete="off" />
{{{ end }}}
<label for="{./id}" class="small stretched-link">
- {{{ if posts.data.crosspostCid }}}[[post-queue:crosspost]]{{{ end }}}
- {{{ if (!posts.data.crosspostCid && posts.data.tid) }}}[[post-queue:reply]]{{{ end }}}
- {{{ if posts.data.cid }}}[[post-queue:topic]]{{{ end }}}
+ {{{ if posts.data.crosspostCid }}}
+ [[post-queue:crosspost]]
+ {{{ else }}}
+ {{{ if posts.data.tid }}}[[post-queue:reply]]{{{ end }}}
+ {{{ if posts.data.cid }}}[[post-queue:topic]]{{{ end }}}
+ {{{ end }}}
</label>
</li>
<li class="card-body d-flex flex-column gap-1 border-bottom">