Node.js based forum software built for the modern web
feat: moving a topic out of cid -1 federates an Announce activity, #12734
Julian Lamdaa665ebc0cf
diff --git a/src/api/activitypub.js b/src/api/activitypub.jsindex a7362056db..4800ea9690 100644--- a/src/api/activitypub.js+++ b/src/api/activitypub.js@@ -17,6 +17,7 @@ const meta = require('../meta');const privileges = require('../privileges');const activitypub = require('../activitypub');const posts = require('../posts');+const topics = require('../topics');const utils = require('../utils');const activitypubApi = module.exports;@@ -111,6 +112,11 @@ async function buildRecipients(object, { pid, uid }) {to = new Set(to);cc = new Set(cc);+ const followersUrl = `${nconf.get('url')}/uid/${uid}/followers`;+ if (!to.has(followersUrl)) {+ cc.add(followersUrl);+ }+const targets = new Set([...followers, ...to, ...cc]);// Remove any ids that aren't asserted actors@@ -290,6 +296,38 @@ activitypubApi.like.note = enabledCheck(async (caller, { pid }) => {});});+activitypubApi.announce = {};++activitypubApi.announce.note = enabledCheck(async (caller, { tid }) => {+ const { mainPid: pid, cid } = await topics.getTopicFields(tid, ['mainPid', 'cid']);++ // Only remote posts can be announced+ if (utils.isNumber(pid)) {+ return;+ }++ const uid = await posts.getPostField(pid, 'uid'); // author+ const allowed = await privileges.posts.can('topics:read', pid, activitypub._constants.uid);+ if (!allowed) {+ // winston.verbose(`[activitypub/api] Not federating announce of pid ${pid} to the fediverse due to privileges.`);+ return;+ }++ const { to, cc, targets } = await buildRecipients({+ to: [`${nconf.get('url')}/uid/${caller.uid}/followers`],+ cc: [uid],+ }, { uid: caller.uid });++ await activitypub.send('uid', caller.uid, Array.from(targets), {+ id: `${nconf.get('url')}/post/${encodeURIComponent(pid)}#activity/announce/${Date.now()}`,+ type: 'Announce',+ to,+ cc,+ object: pid,+ target: `${nconf.get('url')}/category/${cid}`,+ });+});+activitypubApi.undo = {};// activitypubApi.undo.follow =diff --git a/src/api/topics.js b/src/api/topics.jsindex 94b1793519..964d919188 100644--- a/src/api/topics.js+++ b/src/api/topics.js@@ -339,6 +339,7 @@ topicsAPI.move = async (caller, { tid, cid }) => {socketHelpers.emitToUids('event:topic_moved', topicData, notifyUids);if (!topicData.deleted) {socketHelpers.sendNotificationToTopicOwner(tid, caller.uid, 'move', 'notifications:moved-your-topic');+ activitypubApi.announce.note(caller, { tid });}await events.log({