Skip to content

Node.js based forum software built for the modern web

fix(activitypub): always broadcast relay activities to relay followers

Julian Lamf82c7c8e31df
diff --git a/src/activitypub/feps.js b/src/activitypub/feps.js
index ba1bc08917..16947a48d7 100644
--- a/src/activitypub/feps.js
+++ b/src/activitypub/feps.js
@@ -9,7 +9,9 @@ const utils = require('../utils');
const activitypub = module.parent.exports;
const Feps = module.exports;
-Feps.announce = async function announce(id, activity) {
+Feps.announce = async function announce(id, activity, options = {}) {
+ const { fromRelay } = options;
+
let localId;
if (String(id).startsWith(nconf.get('url'))) {
({ id: localId } = await activitypub.helpers.resolveLocalId(id));
@@ -31,13 +33,17 @@ Feps.announce = async function announce(id, activity) {
let relays = await activitypub.relays.list();
relays = relays.reduce((memo, { state, url }) => {
- if (state === 2) {
+ if (state === 2 && !fromRelay) {
memo.push(url);
}
return memo;
}, []);
const followers = localCid ? await activitypub.notes.getCategoryFollowers(cid) : (cid ? [cid] : []);
const targets = relays.concat(followers);
+
+ // Broadcast raw activity to relay followers (always, even when fromRelay — relay followers still need it)
+ await activitypub.relays.broadcast(activity);
+
if (!targets.length) {
return;
}
@@ -81,7 +87,4 @@ Feps.announce = async function announce(id, activity) {
relays.forEach((relay) => {
activitypub.analytics.relays.out(relay);
});
-
- // Broadcast raw activity to relay followers
- await activitypub.relays.broadcast(activity);
};
diff --git a/src/activitypub/inbox.js b/src/activitypub/inbox.js
index 18c5fe2c0f..d92cd53c7f 100644
--- a/src/activitypub/inbox.js
+++ b/src/activitypub/inbox.js
@@ -701,9 +701,9 @@ inbox.announce = async (req) => {
}
}
- // Broadcast to relay followers if we have a pid (skip if relayed — relay already distributes)
- if (pid && !fromRelay) {
- await activitypub.feps.announce(pid, object);
+ // Broadcast to relay followers if we have a pid
+ if (pid) {
+ await activitypub.feps.announce(pid, object, { fromRelay });
}
};
diff --git a/test/activitypub/inbox.js b/test/activitypub/inbox.js
index 01b333f3ee..3654f5ca60 100644
--- a/test/activitypub/inbox.js
+++ b/test/activitypub/inbox.js
@@ -1163,7 +1163,6 @@ describe('Inbox', () => {
it('should broadcast a public activity received via announce to relay followers', async () => {
await db.sortedSetAdd('relays:state', -1, relayActor);
await db.sortedSetAdd('relays:createtime', Date.now(), relayActor);
- await activitypub.relays.add(relayActor);
const { note, id } = helpers.mocks.note();
const { activity: createActivity } = helpers.mocks.create(note);