mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
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:
@@ -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,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user