Node.js based forum software built for the modern web
fix(activitypub): announce dereferenceable objects to relays
Alan Johnson7abe25282aef
diff --git a/src/activitypub/relays.js b/src/activitypub/relays.jsindex 3af52b18b8..fe71537843 100644--- a/src/activitypub/relays.js+++ b/src/activitypub/relays.js@@ -171,11 +171,16 @@ Relays.broadcast = async (payload) => {const followers = await Relays.getFollowers();if (followers.length === 0) return;+ // Create activities use fragment identifiers derived from the created object.+ // A fragment is not sent during HTTP dereference, so relay followers must be+ // given the created object itself rather than the non-dereferenceable Create.+ const object = payload.type === 'Create' && payload.object ? payload.object : payload;+await activitypub.send('uid', 0, followers, {id: `${nconf.get('url')}/post/${encodeURIComponent(payload.id)}#activity/announce/relay/${Date.now()}`,type: 'Announce',actor: `${nconf.get('url')}/actor`,to: [activitypub._constants.publicAddress],- object: payload,+ object,});};diff --git a/test/activitypub/relays.js b/test/activitypub/relays.jsindex e5a00c6436..5d37df8a1e 100644--- a/test/activitypub/relays.js+++ b/test/activitypub/relays.js@@ -47,8 +47,16 @@ describe('ActivityPub Relays', () => {await db.sortedSetRemove('relays:createtime', actor2);});- it('should broadcast to relay followers', async () => {- const payload = { type: 'Create', id: '123' };+ it('should broadcast created objects to relay followers', async () => {+ const object = {+ id: `${nconf.get('url')}/post/123`,+ type: 'Note',+ };+ const payload = {+ id: `${object.id}#activity/create/123456`,+ type: 'Create',+ object,+ };const followers = ['https://f1.com/actor', 'https://f2.com/actor'];// Mock activitypub.send@@ -74,9 +82,11 @@ describe('ActivityPub Relays', () => {const sentPayload = sentTo[0].payload;assert.strictEqual(sentPayload.type, 'Announce');assert.strictEqual(sentPayload.actor, `${nconf.get('url')}/actor`);- assert.deepStrictEqual(sentPayload.object, payload);+ assert.deepStrictEqual(sentPayload.object, object);+ assert.strictEqual(sentPayload.object.id, `${nconf.get('url')}/post/123`);+ assert.ok(!sentPayload.object.id.includes('#activity/create/'));assert.deepStrictEqual(sentPayload.to, ['https://www.w3.org/ns/activitystreams#Public']);- assert.ok(sentPayload.id.startsWith(`${nconf.get('url')}/post/123#activity/announce/relay/`));+ assert.ok(sentPayload.id.startsWith(`${nconf.get('url')}/post/${encodeURIComponent(payload.id)}#activity/announce/relay/`));// Cleanupactivitypub.send = originalSend;