feat: moving a topic out of cid -1 federates an Announce activity, #12734

This commit is contained in:
Julian Lam
2024-08-22 14:45:17 -04:00
parent 76551c7123
commit daa665ebc0
2 changed files with 39 additions and 0 deletions

View File

@@ -17,6 +17,7 @@ const meta = require('../meta');
const privileges = require('../privileges'); const privileges = require('../privileges');
const activitypub = require('../activitypub'); const activitypub = require('../activitypub');
const posts = require('../posts'); const posts = require('../posts');
const topics = require('../topics');
const utils = require('../utils'); const utils = require('../utils');
const activitypubApi = module.exports; const activitypubApi = module.exports;
@@ -111,6 +112,11 @@ async function buildRecipients(object, { pid, uid }) {
to = new Set(to); to = new Set(to);
cc = new Set(cc); 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]); const targets = new Set([...followers, ...to, ...cc]);
// Remove any ids that aren't asserted actors // 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 = {};
// activitypubApi.undo.follow = // activitypubApi.undo.follow =

View File

@@ -339,6 +339,7 @@ topicsAPI.move = async (caller, { tid, cid }) => {
socketHelpers.emitToUids('event:topic_moved', topicData, notifyUids); socketHelpers.emitToUids('event:topic_moved', topicData, notifyUids);
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 });
} }
await events.log({ await events.log({