feat: on post edit, also target anyone who announced the post and their followers

re: #12537
This commit is contained in:
Julian Lam
2024-05-06 15:14:32 -04:00
parent e341a5d868
commit 807c3eac12
2 changed files with 14 additions and 6 deletions

View File

@@ -94,13 +94,12 @@ activitypubApi.unfollow = enabledCheck(async (caller, { type, id, actor }) => {
activitypubApi.create = {};
// this might be better genericised... tbd. some of to/cc is built in mocks.
async function buildRecipients(object, uid) {
async function buildRecipients(object, { pid, uid }) {
const followers = await db.getSortedSetMembers(`followersRemote:${uid}`);
let { to, cc } = object;
to = new Set(to);
cc = new Set(cc);
// Directly address user if inReplyTo
const parentId = await posts.getPostField(object.inReplyTo, 'uid');
if (activitypub.helpers.isUri(parentId) && to.has(parentId)) {
@@ -111,6 +110,15 @@ async function buildRecipients(object, uid) {
targets.delete(`${nconf.get('url')}/uid/${uid}/followers`); // followers URL not targeted
targets.delete(activitypub._constants.publicAddress); // public address not targeted
// Announcers and their followers
if (pid) {
const announcers = (await activitypub.notes.announce.list({ pid })).map(({ actor }) => actor);
const announcersFollowers = (await user.getUsersFields(announcers, ['followersUrl']))
.filter(o => o.hasOwnProperty('followersUrl'))
.map(({ followersUrl }) => followersUrl);
[...announcers, ...announcersFollowers].forEach(uri => targets.add(uri));
}
object.to = Array.from(to);
object.cc = Array.from(cc);
return { targets };
@@ -129,7 +137,7 @@ activitypubApi.create.post = enabledCheck(async (caller, { pid }) => {
}
const object = await activitypub.mocks.note(post);
const { targets } = await buildRecipients(object, post.user.uid);
const { targets } = await buildRecipients(object, { uid: post.user.uid });
const { cid } = post.category;
const followers = await activitypub.notes.getCategoryFollowers(cid);
@@ -175,7 +183,7 @@ activitypubApi.update.profile = enabledCheck(async (caller, { uid }) => {
activitypubApi.update.note = enabledCheck(async (caller, { post }) => {
const object = await activitypub.mocks.note(post);
const { targets } = await buildRecipients(object, post.user.uid);
const { targets } = await buildRecipients(object, { pid: post.pid, uid: post.user.uid });
const allowed = await privileges.posts.can('topics:read', post.pid, activitypub._constants.uid);
if (!allowed) {