From 09d8fbf97849be3512fd1f67707a2fa2cc6798a4 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 25 Jun 2024 11:38:13 -0400 Subject: [PATCH] feat: send out `Update(Actor)` when a category is edited This commit also updates the activity sent out when a user profile is edited. The activity is now sent to all known actors. closes #12655 --- src/api/activitypub.js | 21 ++++++++++++++++++--- src/api/categories.js | 3 +++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/api/activitypub.js b/src/api/activitypub.js index 5ca442fbd5..42969e8d0a 100644 --- a/src/api/activitypub.js +++ b/src/api/activitypub.js @@ -172,12 +172,27 @@ activitypubApi.create.note = enabledCheck(async (caller, { pid }) => { activitypubApi.update = {}; activitypubApi.update.profile = enabledCheck(async (caller, { uid }) => { - const [object, followers] = await Promise.all([ + const [object, targets] = await Promise.all([ activitypub.mocks.actors.user(uid), - db.getSortedSetMembers(`followersRemote:${caller.uid}`), + db.getSortedSetMembers('usersRemote:lastCrawled'), ]); - await activitypub.send('uid', caller.uid, followers, { + await activitypub.send('uid', caller.uid, targets, { + id: `${object.id}#activity/update/${Date.now()}`, + type: 'Update', + to: [activitypub._constants.publicAddress], + cc: [], + object, + }); +}); + +activitypubApi.update.category = enabledCheck(async (caller, { cid }) => { + const [object, targets] = await Promise.all([ + activitypub.mocks.actors.category(cid), + db.getSortedSetMembers('usersRemote:lastCrawled'), + ]); + + await activitypub.send('cid', cid, targets, { id: `${object.id}#activity/update/${Date.now()}`, type: 'Update', to: [activitypub._constants.publicAddress], diff --git a/src/api/categories.js b/src/api/categories.js index 9a43a81526..68c28caebd 100644 --- a/src/api/categories.js +++ b/src/api/categories.js @@ -8,6 +8,8 @@ const user = require('../user'); const groups = require('../groups'); const privileges = require('../privileges'); +const activitypubApi = require('./activitypub'); + const categoriesAPI = module.exports; const hasAdminPrivilege = async (uid, privilege = 'categories') => { @@ -63,6 +65,7 @@ categoriesAPI.update = async function (caller, data) { const payload = {}; payload[cid] = values; await categories.update(payload); + await activitypubApi.update.category(caller, { cid }); }; categoriesAPI.delete = async function (caller, { cid }) {