mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: handle receipt of Add activity #12707
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 locally
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user