feat: update buildRecipients to include all topic participants and their followers, #12735

This commit is contained in:
Julian Lam
2024-09-18 14:35:42 -04:00
parent 71ce308936
commit 6752a54116

View File

@@ -106,6 +106,7 @@ async function buildRecipients(object, { pid, uid }) {
/** /**
* - Builds a list of targets for activitypub.send to consume * - Builds a list of targets for activitypub.send to consume
* - Extends to and cc since the activity can be addressed more widely * - Extends to and cc since the activity can be addressed more widely
* - `pid` is optional, but if included, includes announcers and all authors up the toPid chain
*/ */
const followers = await db.getSortedSetMembers(`followersRemote:${uid}`); const followers = await db.getSortedSetMembers(`followersRemote:${uid}`);
let { to, cc } = object; let { to, cc } = object;
@@ -127,14 +128,18 @@ async function buildRecipients(object, { pid, uid }) {
} }
}); });
// Announcers and their followers // Topic posters, post announcers and their followers
if (pid) { if (pid) {
const tid = await posts.getPostField(pid, 'tid');
const participants = (await db.getSortedSetMembers(`tid:${tid}:posters`))
.filter(uid => !utils.isNumber(uid)); // remote users only
const announcers = (await activitypub.notes.announce.list({ pid })).map(({ actor }) => actor); const announcers = (await activitypub.notes.announce.list({ pid })).map(({ actor }) => actor);
const announcersFollowers = (await user.getUsersFields(announcers, ['followersUrl'])) const auxiliaries = Array.from(new Set([...participants, ...announcers]));
const auxiliaryFollowers = (await user.getUsersFields(auxiliaries, ['followersUrl']))
.filter(o => o.hasOwnProperty('followersUrl')) .filter(o => o.hasOwnProperty('followersUrl'))
.map(({ followersUrl }) => followersUrl); .map(({ followersUrl }) => followersUrl);
[...announcers].forEach(uri => targets.add(uri)); [...auxiliaries].forEach(uri => targets.add(uri));
[...announcers, ...announcersFollowers].forEach(uri => cc.add(uri)); [...auxiliaries, ...auxiliaryFollowers].forEach(uri => cc.add(uri));
} }
return { return {
@@ -161,7 +166,7 @@ activitypubApi.create.note = enabledCheck(async (caller, { pid, post }) => {
} }
const object = await activitypub.mocks.note(post); const object = await activitypub.mocks.note(post);
const { to, cc, targets } = await buildRecipients(object, { uid: post.user.uid }); const { to, cc, targets } = await buildRecipients(object, { pid, uid: post.user.uid });
const { cid } = post.category; const { cid } = post.category;
const followers = await activitypub.notes.getCategoryFollowers(cid); const followers = await activitypub.notes.getCategoryFollowers(cid);
@@ -318,6 +323,7 @@ activitypubApi.announce.note = enabledCheck(async (caller, { tid }) => {
} }
const { to, cc, targets } = await buildRecipients({ const { to, cc, targets } = await buildRecipients({
id: pid,
to: [activitypub._constants.publicAddress], to: [activitypub._constants.publicAddress],
cc: [`${nconf.get('url')}/uid/${caller.uid}/followers`, uid], cc: [`${nconf.get('url')}/uid/${caller.uid}/followers`, uid],
}, { uid: caller.uid }); }, { uid: caller.uid });