mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-20 15:30:39 +01:00
feat: federate out undo(announce) when moving topics
This commit is contained in:
@@ -307,7 +307,6 @@ Out.announce.topic = enabledCheck(async (tid) => {
|
|||||||
to,
|
to,
|
||||||
cc,
|
cc,
|
||||||
object: pid,
|
object: pid,
|
||||||
target: `${nconf.get('url')}/category/${cid}`,
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -525,3 +524,52 @@ Out.undo.flag = enabledCheck(async (uid, flag) => {
|
|||||||
});
|
});
|
||||||
await db.sortedSetRemove(`flag:${flag.flagId}:remote`, uid);
|
await db.sortedSetRemove(`flag:${flag.flagId}:remote`, uid);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Out.undo.announce = enabledCheck(async (type, id, tid) => {
|
||||||
|
if (!utils.isNumber(id) || !['uid', 'cid'].includes(type)) {
|
||||||
|
throw new Error('[[error:invalid-data]]');
|
||||||
|
}
|
||||||
|
|
||||||
|
const exists = await Promise.all([
|
||||||
|
topics.exists(tid),
|
||||||
|
type === 'uid' ? user.exists(id) : categories.exists(id),
|
||||||
|
]);
|
||||||
|
if (!exists.every(Boolean)) {
|
||||||
|
throw new Error('[[error:invalid-data]]');
|
||||||
|
}
|
||||||
|
|
||||||
|
const baseUrl = `${nconf.get('url')}/${type === 'uid' ? 'uid' : 'category'}/${id}`;
|
||||||
|
const { uid, mainPid: pid } = await topics.getTopicFields(tid, ['uid', 'mainPid']);
|
||||||
|
const allowed = await privileges.topics.can('topics:read', tid, activitypub._constants.uid);
|
||||||
|
if (!allowed) {
|
||||||
|
activitypub.helpers.log(`[activitypub/api] Not federating announce of pid ${pid} to the fediverse due to privileges.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { to, cc, targets } = await activitypub.buildRecipients({
|
||||||
|
id: pid,
|
||||||
|
to: [activitypub._constants.publicAddress],
|
||||||
|
cc: [`${baseUrl}/followers`, uid],
|
||||||
|
}, {
|
||||||
|
uid: type === 'uid' && id,
|
||||||
|
cid: type === 'cid' && id,
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// Just undo the announce.
|
||||||
|
await activitypub.send(type, id, Array.from(targets), {
|
||||||
|
id: `${nconf.get('url')}/post/${encodeURIComponent(pid)}#activity/undo:announce/${Date.now()}`,
|
||||||
|
type: 'Undo',
|
||||||
|
actor: baseUrl,
|
||||||
|
to,
|
||||||
|
cc,
|
||||||
|
object: {
|
||||||
|
id: `${nconf.get('url')}/post/${encodeURIComponent(pid)}#activity/announce/${Date.now()}`, // wrong timestamp btw
|
||||||
|
type: 'Announce',
|
||||||
|
actor: baseUrl,
|
||||||
|
to,
|
||||||
|
cc,
|
||||||
|
object: pid,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -330,6 +330,7 @@ topicsAPI.move = async (caller, { tid, cid }) => {
|
|||||||
activitypub.out.move.context(caller.uid, tid);
|
activitypub.out.move.context(caller.uid, tid);
|
||||||
activitypub.out.announce.topic(tid);
|
activitypub.out.announce.topic(tid);
|
||||||
}
|
}
|
||||||
|
activitypub.out.undo.announce('cid', topicData.cid, tid);
|
||||||
}
|
}
|
||||||
|
|
||||||
await events.log({
|
await events.log({
|
||||||
|
|||||||
Reference in New Issue
Block a user