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

closes #13097
This commit is contained in:
Julian Lam
2025-02-14 21:07:23 -05:00
parent 637addc445
commit b7f9983a2f
2 changed files with 32 additions and 2 deletions

View File

@@ -25,7 +25,7 @@ Feps.announce = async function announce(id, activity) {
followers.unshift(actor); 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 Promise.all([activity, activity.object].map(async (object) => {
await activitypub.send('cid', cid, followers, { await activitypub.send('cid', cid, followers, {
id: `${nconf.get('url')}/post/${encodeURIComponent(id)}#activity/announce/${Date.now()}`, 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,
});
};

View File

@@ -10,6 +10,7 @@ const meta = require('../meta');
const privileges = require('../privileges'); const privileges = require('../privileges');
const events = require('../events'); const events = require('../events');
const batch = require('../batch'); const batch = require('../batch');
const activitypub = require('../activitypub');
const activitypubApi = require('./activitypub'); const activitypubApi = require('./activitypub');
const apiHelpers = require('./helpers'); const apiHelpers = require('./helpers');
@@ -327,7 +328,7 @@ topicsAPI.move = async (caller, { tid, cid }) => {
if (!canMove) { if (!canMove) {
throw new Error('[[error:no-privileges]]'); 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)) { if (!cids.includes(topicData.cid)) {
cids.push(topicData.cid); cids.push(topicData.cid);
} }
@@ -341,6 +342,7 @@ topicsAPI.move = async (caller, { tid, cid }) => {
if (!topicData.deleted) { if (!topicData.deleted) {
socketHelpers.sendNotificationToTopicOwner(tid, caller.uid, 'move', 'notifications:moved-your-topic'); socketHelpers.sendNotificationToTopicOwner(tid, caller.uid, 'move', 'notifications:moved-your-topic');
activitypubApi.announce.note(caller, { tid }); activitypubApi.announce.note(caller, { tid });
activitypub.feps.announceObject(topicData.mainPid);
} }
await events.log({ await events.log({