Skip to content

Commit

Permalink
feat: have category actor send Announce(Note) activity on posts from …
Browse files Browse the repository at this point in the history
…that cid

re: #12434
  • Loading branch information
julianlam committed Mar 22, 2024
1 parent 803975f commit 7df5cab
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/activitypub/notes.js
Expand Up @@ -254,3 +254,11 @@ Notes.syncUserInboxes = async function (tid) {
winston.verbose(`[activitypub/syncUserInboxes] Syncing tid ${tid} with ${uids.size} inboxes`);
await db.sortedSetsAdd(keys, keys.map(() => score || Date.now()), tid);
};

Notes.getCategoryFollowers = async (cid) => {
// Retrieves remote users who have followed a category; used to build recipient list
let uids = await db.getSortedSetRangeByScore(`cid:${cid}:uid:watch:state`, 0, -1, categories.watchStates.tracking, categories.watchStates.tracking);
uids = uids.filter(uid => !utils.isNumber(uid));

return uids;
};
25 changes: 18 additions & 7 deletions src/api/activitypub.js
Expand Up @@ -104,15 +104,26 @@ activitypubApi.create.post = enabledCheck(async (caller, { pid }) => {

const object = await activitypub.mocks.note(post);
const { targets } = await buildRecipients(object, post.user.uid);

const payload = {
type: 'Create',
to: object.to,
cc: object.cc,
object,
const { cid } = post.category;
const followers = await activitypub.notes.getCategoryFollowers(cid);

const payloads = {
create: {
type: 'Create',
to: object.to,
cc: object.cc,
object,
},
announce: {
type: 'Announce',
to: [`${nconf.get('url')}/category/${cid}/followers`],
cc: [activitypub._constants.publicAddress],
object,
},
};

await activitypub.send('uid', caller.uid, Array.from(targets), payload);
await activitypub.send('uid', caller.uid, Array.from(targets), payloads.create);
await activitypub.send('cid', cid, followers, payloads.announce);
});

activitypubApi.update = {};
Expand Down

0 comments on commit 7df5cab

Please sign in to comment.