Skip to content

Commit

Permalink
feat: on post edit, also target anyone who announced the post and the…
Browse files Browse the repository at this point in the history
…ir followers

re: #12537
  • Loading branch information
julianlam committed May 6, 2024
1 parent e341a5d commit 807c3ea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 12 additions & 4 deletions src/api/activitypub.js
Expand Up @@ -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)) {
Expand All @@ -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 };
Expand All @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/upgrades/4.0.0/remote_user_urls.js
Expand Up @@ -15,8 +15,8 @@ module.exports = {

let actorIds = await db.getSortedSetMembers('usersRemote:lastCrawled');
progress.total = actorIds.length;
const exists = await Promise.all(actorIds.map(async id => await db.isObjectField(`userRemote:${id}`, 'url')));
actorIds = actorIds.filter((id, idx) => !exists[idx]);
const exists = await Promise.all(actorIds.map(async id => await db.isObjectFields(`userRemote:${id}`, ['url', 'followersUrl'])));
actorIds = actorIds.filter((id, idx) => !exists[idx].every(Boolean));

// Increment ones that were already completed
progress.incr(progress.total - actorIds.length);
Expand Down

0 comments on commit 807c3ea

Please sign in to comment.