feat: handle receipt of Add activity #12707

This commit is contained in:
Julian Lam
2024-10-24 14:36:37 -04:00
parent 6f237c57cd
commit 3023b25172
3 changed files with 21 additions and 2 deletions

View File

@@ -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) => { inbox.update = async (req) => {
const { actor, object } = req.body; const { actor, object } = req.body;
const isPublic = [...(object.to || []), ...(object.cc || [])].includes(activitypub._constants.publicAddress); const isPublic = [...(object.to || []), ...(object.cc || [])].includes(activitypub._constants.publicAddress);

View File

@@ -425,6 +425,9 @@ Mocks.notes.public = async (post) => {
return payload; return payload;
}); });
let context = await posts.getPostField(post.pid, 'context');
context = context || `${nconf.get('url')}/topic/${post.topic.tid}`;
const object = { const object = {
'@context': 'https://www.w3.org/ns/activitystreams', '@context': 'https://www.w3.org/ns/activitystreams',
id, id,
@@ -436,7 +439,7 @@ Mocks.notes.public = async (post) => {
updated, updated,
url: id, url: id,
attributedTo: `${nconf.get('url')}/uid/${post.user.uid}`, 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}`, audience: `${nconf.get('url')}/category/${post.category.cid}`,
summary: null, summary: null,
name, name,

View File

@@ -388,7 +388,7 @@ activitypubApi.add = enabledCheck((async (_, { pid }) => {
const tid = await posts.getPostField(localId || pid, 'tid'); const tid = await posts.getPostField(localId || pid, 'tid');
const cid = await posts.getCidByPid(localId || pid); const cid = await posts.getCidByPid(localId || pid);
if (cid <= 0) { if (!utils.isNumber(tid) || cid <= 0) { // `Add` only federated on categorized topics started locally
return; return;
} }