Skip to content

Node.js based forum software built for the modern web

refactor: user announces no longer occur on topic move. Instead, the new category announces. Only occurs when topic moved to local categories.

Julian Lame09bb8b611ac
diff --git a/src/api/activitypub.js b/src/api/activitypub.js
index 19e9087539..3d1d3ff546 100644
--- a/src/api/activitypub.js
+++ b/src/api/activitypub.js
@@ -347,7 +347,40 @@ activitypubApi.like.note = enabledCheck(async (caller, { pid }) => {
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']);
// Only remote posts can be announced to local categories
diff --git a/src/api/topics.js b/src/api/topics.js
index e0f149e392..38468f5956 100644
--- a/src/api/topics.js
+++ b/src/api/topics.js
@@ -326,8 +326,7 @@ topicsAPI.move = async (caller, { tid, cid }) => {
await activitypubApi.announce.delete({ uid: caller.uid }, { tid });
// tbd: activitypubApi.undo.announce?
} else {
- // tbd: some kind of plain object announce by the category...
- activitypubApi.announce.note(caller, { tid }); // user announce, remove when discrete announces are a thing
+ activitypubApi.announce.category(caller, { tid });
// tbd: api.activitypub.announce.move
}
}