mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-28 09:36:16 +01:00
feat: have category actor send Announce(Note) on remote replies to topics in a cid
#12434
This commit is contained in:
@@ -25,7 +25,7 @@ inbox.create = async (req) => {
|
|||||||
throw new Error('[[error:activitypub.not-implemented]]');
|
throw new Error('[[error:activitypub.not-implemented]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
const { tid, count } = await activitypub.notes.assertTopic(0, object.id);
|
const { tid, count } = await activitypub.notes.assert(0, object.id);
|
||||||
winston.verbose(`[activitypub/inbox] Parsing ${count} notes into topic ${tid}`);
|
winston.verbose(`[activitypub/inbox] Parsing ${count} notes into topic ${tid}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ inbox.update = async (req) => {
|
|||||||
if (exists) {
|
if (exists) {
|
||||||
await posts.edit(postData);
|
await posts.edit(postData);
|
||||||
} else {
|
} else {
|
||||||
await activitypub.notes.assertTopic(0, object.id);
|
await activitypub.notes.assert(0, object.id);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
activitypub.send('uid', 0, actor, {
|
activitypub.send('uid', 0, actor, {
|
||||||
@@ -129,7 +129,7 @@ inbox.announce = async (req) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
({ tid } = await activitypub.notes.assertTopic(0, pid));
|
({ tid } = await activitypub.notes.assert(0, pid, object));
|
||||||
if (!tid) {
|
if (!tid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const winston = require('winston');
|
const winston = require('winston');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
|
const nconf = require('nconf');
|
||||||
|
|
||||||
const db = require('../database');
|
const db = require('../database');
|
||||||
const meta = require('../meta');
|
const meta = require('../meta');
|
||||||
@@ -15,15 +16,15 @@ const utils = require('../utils');
|
|||||||
const activitypub = module.parent.exports;
|
const activitypub = module.parent.exports;
|
||||||
const Notes = module.exports;
|
const Notes = module.exports;
|
||||||
|
|
||||||
Notes.assert = async (uid, id) => {
|
Notes.assert = async (uid, id, object) => {
|
||||||
/**
|
/**
|
||||||
* Given the id of any post, traverses up to cache the entire threaded context
|
* Given the id (or optional AS object) of any post, traverses up to cache the entire threaded context
|
||||||
*
|
*
|
||||||
* Unfortunately, due to limitations and fragmentation of the existing ActivityPub landscape,
|
* Unfortunately, due to limitations and fragmentation of the existing ActivityPub landscape,
|
||||||
* retrieving the entire reply tree is not possible at this time.
|
* retrieving the entire reply tree is not possible at this time.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const chain = Array.from(await Notes.getParentChain(uid, id));
|
const chain = Array.from(await Notes.getParentChain(uid, object || id));
|
||||||
if (!chain.length) {
|
if (!chain.length) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -124,6 +125,19 @@ Notes.assert = async (uid, id) => {
|
|||||||
Notes.updateLocalRecipients(post.pid, { to, cc }),
|
Notes.updateLocalRecipients(post.pid, { to, cc }),
|
||||||
Notes.saveAttachments(post.pid, attachment),
|
Notes.saveAttachments(post.pid, attachment),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// Category announce
|
||||||
|
if (id === post.id) {
|
||||||
|
// eslint-disable-next-line no-await-in-loop
|
||||||
|
const followers = await activitypub.notes.getCategoryFollowers(cid);
|
||||||
|
// eslint-disable-next-line no-await-in-loop
|
||||||
|
await activitypub.send('cid', cid, followers, {
|
||||||
|
type: 'Announce',
|
||||||
|
to: [`${nconf.get('url')}/category/${cid}/followers`],
|
||||||
|
cc: [activitypub._constants.publicAddress],
|
||||||
|
object,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await Notes.syncUserInboxes(tid);
|
await Notes.syncUserInboxes(tid);
|
||||||
@@ -213,9 +227,9 @@ Notes.getParentChain = async (uid, input) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let object;
|
let object = !activitypub.helpers.isUri(input) && input.id === id ? input : undefined;
|
||||||
try {
|
try {
|
||||||
object = await activitypub.get('uid', uid, id);
|
object = object || await activitypub.get('uid', uid, id);
|
||||||
|
|
||||||
// Handle incorrect id passed in
|
// Handle incorrect id passed in
|
||||||
if (id !== object.id) {
|
if (id !== object.id) {
|
||||||
|
|||||||
@@ -123,7 +123,9 @@ activitypubApi.create.post = enabledCheck(async (caller, { pid }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
await activitypub.send('uid', caller.uid, Array.from(targets), payloads.create);
|
await activitypub.send('uid', caller.uid, Array.from(targets), payloads.create);
|
||||||
|
if (followers.length) {
|
||||||
await activitypub.send('cid', cid, followers, payloads.announce);
|
await activitypub.send('cid', cid, followers, payloads.announce);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
activitypubApi.update = {};
|
activitypubApi.update = {};
|
||||||
|
|||||||
Reference in New Issue
Block a user