Skip to content

Node.js based forum software built for the modern web

fix: update buildRecipents to add option to skip target creation step, update ap actors for note to not bother building targets

Julian Lamad27347fa208
diff --git a/src/activitypub/index.js b/src/activitypub/index.js
index b3ae1e83a1..2f761b943a 100644
--- a/src/activitypub/index.js
+++ b/src/activitypub/index.js
@@ -456,7 +456,7 @@ ActivityPub.record = async ({ id, type, actor }) => {
]);
};
-ActivityPub.buildRecipients = async function (object, { pid, uid, cid }) {
+ActivityPub.buildRecipients = async function (object, options) {
/**
* - Builds a list of targets for activitypub.send to consume
* - Extends to and cc since the activity can be addressed more widely
@@ -464,14 +464,18 @@ ActivityPub.buildRecipients = async function (object, { pid, uid, cid }) {
* - `cid`: includes followers of the passed-in cid (local only, can also be an array)
* - `uid`: includes followers of the passed-in uid (local only)
* - `pid`: includes post announcers and all topic participants
+ * - `targets`: boolean; whether to calculate targets (default: true)
*/
let { to, cc } = object;
to = new Set(to);
cc = new Set(cc);
+ let { pid, uid, cid } = options;
+ options.targets = options.targets ?? true;
+
let followers = [];
if (uid) {
- followers = await db.getSortedSetMembers(`followersRemote:${uid}`);
+ ({ uids: followers } = await ActivityPub.actors.getFollowers(uid));
const followersUrl = `${nconf.get('url')}/uid/${uid}/followers`;
if (!to.has(followersUrl)) {
cc.add(followersUrl);
@@ -490,24 +494,28 @@ ActivityPub.buildRecipients = async function (object, { pid, uid, cid }) {
}));
}
- const targets = new Set([...followers, ...to, ...cc]);
+ let targets = new Set();
+ if (options.targets) {
+ targets = new Set([...followers, ...to, ...cc]);
- // Remove local uris, public addresses, and any ids that aren't asserted actors
- targets.forEach((address) => {
- if (address.startsWith(nconf.get('url'))) {
- targets.delete(address);
- }
- });
- ActivityPub._constants.acceptablePublicAddresses.forEach((address) => {
- targets.delete(address);
- });
- if (targets.size) {
- const exists = await db.isSortedSetMembers('usersRemote:lastCrawled', [...targets]);
- Array.from(targets).forEach((uri, idx) => {
- if (!exists[idx]) {
- targets.delete(uri);
+ // Remove local uris, public addresses, and any ids that aren't asserted actors
+ targets.forEach((address) => {
+ if (address.startsWith(nconf.get('url'))) {
+ targets.delete(address);
}
});
+ ActivityPub._constants.acceptablePublicAddresses.forEach((address) => {
+ targets.delete(address);
+ });
+ if (targets.size) {
+ console.log('derpo', new Error().stack);
+ const exists = await db.isSortedSetMembers('usersRemote:lastCrawled', [...targets]);
+ Array.from(targets).forEach((uri, idx) => {
+ if (!exists[idx]) {
+ targets.delete(uri);
+ }
+ });
+ }
}
// Topic posters, post announcers and their followers
diff --git a/src/controllers/activitypub/actors.js b/src/controllers/activitypub/actors.js
index 9ae24ed613..dddd402f2d 100644
--- a/src/controllers/activitypub/actors.js
+++ b/src/controllers/activitypub/actors.js
@@ -77,7 +77,7 @@ Actors.note = async function (req, res, next) {
}
const payload = await activitypub.mocks.notes.public(post);
- const { to, cc } = await activitypub.buildRecipients(payload, { pid: post.pid, uid: post.user.uid });
+ const { to, cc } = await activitypub.buildRecipients(payload, { pid: post.pid, uid: post.user.uid, targets: false });
payload.to = to;
payload.cc = cc;