mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: moving a topic out of cid -1 federates an Announce activity, #12734
This commit is contained in:
@@ -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 =
|
||||||
|
|||||||
@@ -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({
|
||||||
|
|||||||
Reference in New Issue
Block a user