Skip to content

Node.js based forum software built for the modern web

feat: federate out Announce of a tid's mainPid if the tid is moved out of cid -1

Julian Lamb7f9983a2feb
diff --git a/src/activitypub/feps.js b/src/activitypub/feps.js
index bfed682671..4cb0b8821c 100644
--- a/src/activitypub/feps.js
+++ b/src/activitypub/feps.js
@@ -25,7 +25,7 @@ Feps.announce = async function announce(id, activity) {
followers.unshift(actor);
}
- winston.info(`[activitypub/inbox.announce(1b12)] Announcing ${activity.type} to followers of cid ${cid}`);
+ activitypub.helpers.log(`[activitypub/inbox.announce(1b12)] Announcing ${activity.type} (${activity.id}) to followers of cid ${cid}`);
await Promise.all([activity, activity.object].map(async (object) => {
await activitypub.send('cid', cid, followers, {
id: `${nconf.get('url')}/post/${encodeURIComponent(id)}#activity/announce/${Date.now()}`,
@@ -37,3 +37,31 @@ Feps.announce = async function announce(id, activity) {
});
}));
};
+
+Feps.announceObject = async function announceObject(id) {
+ let localId;
+ if (String(id).startsWith(nconf.get('url'))) {
+ ({ id: localId } = await activitypub.helpers.resolveLocalId(id));
+ }
+ const cid = await posts.getCidByPid(localId || id);
+
+ const followers = await activitypub.notes.getCategoryFollowers(cid);
+ if (!followers.length) {
+ return;
+ }
+
+ const author = await posts.getPostField(id, 'uid');
+ if (!author.startsWith(nconf.get('url'))) {
+ followers.unshift(author);
+ }
+
+ activitypub.helpers.log(`[activitypub/inbox.announce(1b12)] Announcing object (${id}) to followers of cid ${cid}`);
+ await activitypub.send('cid', cid, followers, {
+ id: `${nconf.get('url')}/post/${encodeURIComponent(id)}#activity/announce/${Date.now()}`,
+ type: 'Announce',
+ actor: `${nconf.get('url')}/category/${cid}`,
+ to: [`${nconf.get('url')}/category/${cid}/followers`],
+ cc: [author, activitypub._constants.publicAddress],
+ object: id,
+ });
+};
diff --git a/src/api/topics.js b/src/api/topics.js
index b9066786a0..f1e9f9408a 100644
--- a/src/api/topics.js
+++ b/src/api/topics.js
@@ -10,6 +10,7 @@ const meta = require('../meta');
const privileges = require('../privileges');
const events = require('../events');
const batch = require('../batch');
+const activitypub = require('../activitypub');
const activitypubApi = require('./activitypub');
const apiHelpers = require('./helpers');
@@ -327,7 +328,7 @@ topicsAPI.move = async (caller, { tid, cid }) => {
if (!canMove) {
throw new Error('[[error:no-privileges]]');
}
- const topicData = await topics.getTopicFields(tid, ['tid', 'cid', 'slug', 'deleted']);
+ const topicData = await topics.getTopicFields(tid, ['tid', 'cid', 'mainPid', 'slug', 'deleted']);
if (!cids.includes(topicData.cid)) {
cids.push(topicData.cid);
}
@@ -341,6 +342,7 @@ topicsAPI.move = async (caller, { tid, cid }) => {
if (!topicData.deleted) {
socketHelpers.sendNotificationToTopicOwner(tid, caller.uid, 'move', 'notifications:moved-your-topic');
activitypubApi.announce.note(caller, { tid });
+ activitypub.feps.announceObject(topicData.mainPid);
}
await events.log({