Node.js based forum software built for the modern web
feat: handle receipt of `Add` activity #12707
Julian Lam3023b2517227
diff --git a/src/activitypub/inbox.js b/src/activitypub/inbox.jsindex a3a6648aa3..5e20d417f6 100644--- a/src/activitypub/inbox.js+++ b/src/activitypub/inbox.js@@ -76,6 +76,22 @@ inbox.create = async (req) => {}};+inbox.add = async (req) => {+ const { object, target } = req.body;++ // Only react on Adds pertaining to local posts+ const { type, id: pid } = await activitypub.helpers.resolveLocalId(object);+ if (type === 'post') {+ // Check context of OP+ const tid = await posts.getPostField(pid, 'tid');+ const context = await topics.getTopicField(tid, 'context');+ if (context && context === target) {+ activitypub.helpers.log(`[activitypub/inbox/add] Associating pid ${pid} with new context ${target}`);+ await posts.setPostField(pid, 'context', target);+ }+ }+};+inbox.update = async (req) => {const { actor, object } = req.body;const isPublic = [...(object.to || []), ...(object.cc || [])].includes(activitypub._constants.publicAddress);diff --git a/src/activitypub/mocks.js b/src/activitypub/mocks.jsindex 09f6eeb934..5681425843 100644--- a/src/activitypub/mocks.js+++ b/src/activitypub/mocks.js@@ -425,6 +425,9 @@ Mocks.notes.public = async (post) => {return payload;});+ let context = await posts.getPostField(post.pid, 'context');+ context = context || `${nconf.get('url')}/topic/${post.topic.tid}`;+const object = {'@context': 'https://www.w3.org/ns/activitystreams',id,@@ -436,7 +439,7 @@ Mocks.notes.public = async (post) => {updated,url: id,attributedTo: `${nconf.get('url')}/uid/${post.user.uid}`,- context: `${nconf.get('url')}/topic/${post.topic.tid}`,+ context,audience: `${nconf.get('url')}/category/${post.category.cid}`,summary: null,name,diff --git a/src/api/activitypub.js b/src/api/activitypub.jsindex 57870db800..b38f6bbc78 100644--- a/src/api/activitypub.js+++ b/src/api/activitypub.js@@ -388,7 +388,7 @@ activitypubApi.add = enabledCheck((async (_, { pid }) => {const tid = await posts.getPostField(localId || pid, 'tid');const cid = await posts.getCidByPid(localId || pid);- if (cid <= 0) {+ if (!utils.isNumber(tid) || cid <= 0) { // `Add` only federated on categorized topics started locallyreturn;}