mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-16 21:40:23 +01:00
refactor: user announces no longer occur on topic move. Instead, the new category announces. Only occurs when topic moved to local categories.
This commit is contained in:
@@ -347,7 +347,40 @@ activitypubApi.like.note = enabledCheck(async (caller, { pid }) => {
|
|||||||
|
|
||||||
activitypubApi.announce = {};
|
activitypubApi.announce = {};
|
||||||
|
|
||||||
activitypubApi.announce.note = enabledCheck(async (caller, { tid }) => {
|
activitypubApi.announce.category = enabledCheck(async (_, { tid }) => {
|
||||||
|
const { mainPid: pid, cid } = await topics.getTopicFields(tid, ['mainPid', 'cid']);
|
||||||
|
|
||||||
|
// Only local categories can announce
|
||||||
|
if (!utils.isNumber(cid) || parseInt(cid, 10) < 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uid = await posts.getPostField(pid, 'uid'); // author
|
||||||
|
const allowed = await privileges.posts.can('topics:read', pid, 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: [`${nconf.get('url')}/category/${cid}/followers`, uid],
|
||||||
|
}, { cid, uid: utils.isNumber(uid) ? uid : undefined });
|
||||||
|
|
||||||
|
await activitypub.send('cid', cid, Array.from(targets), {
|
||||||
|
id: `${nconf.get('url')}/post/${encodeURIComponent(pid)}#activity/announce/${Date.now()}`,
|
||||||
|
type: 'Announce',
|
||||||
|
actor: `${nconf.get('url')}/category/${cid}`,
|
||||||
|
to,
|
||||||
|
cc,
|
||||||
|
object: pid,
|
||||||
|
target: `${nconf.get('url')}/category/${cid}`,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
activitypubApi.announce.user = enabledCheck(async (caller, { tid }) => {
|
||||||
|
// ORPHANED, but will re-use when user announces are a thing.
|
||||||
const { mainPid: pid, cid } = await topics.getTopicFields(tid, ['mainPid', 'cid']);
|
const { mainPid: pid, cid } = await topics.getTopicFields(tid, ['mainPid', 'cid']);
|
||||||
|
|
||||||
// Only remote posts can be announced to local categories
|
// Only remote posts can be announced to local categories
|
||||||
|
|||||||
@@ -326,8 +326,7 @@ topicsAPI.move = async (caller, { tid, cid }) => {
|
|||||||
await activitypubApi.announce.delete({ uid: caller.uid }, { tid });
|
await activitypubApi.announce.delete({ uid: caller.uid }, { tid });
|
||||||
// tbd: activitypubApi.undo.announce?
|
// tbd: activitypubApi.undo.announce?
|
||||||
} else {
|
} else {
|
||||||
// tbd: some kind of plain object announce by the category...
|
activitypubApi.announce.category(caller, { tid });
|
||||||
activitypubApi.announce.note(caller, { tid }); // user announce, remove when discrete announces are a thing
|
|
||||||
// tbd: api.activitypub.announce.move
|
// tbd: api.activitypub.announce.move
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user