From c8bc6e551b722c5bf2f63f3ddc707c1ac0b4e9ba Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 14 Jun 2024 13:37:46 -0400 Subject: [PATCH] fix: 1b12 conformance for inbox.create as well --- src/activitypub/inbox.js | 16 +++++++++------- src/api/activitypub.js | 29 +++++++++-------------------- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/src/activitypub/inbox.js b/src/activitypub/inbox.js index e988d69d91..56e199a300 100644 --- a/src/activitypub/inbox.js +++ b/src/activitypub/inbox.js @@ -47,13 +47,15 @@ inbox.create = async (req) => { const cid = await topics.getTopicField(response.tid, 'cid'); const followers = await activitypub.notes.getCategoryFollowers(cid); if (followers.length) { - await activitypub.send('cid', cid, followers, { - id: `${object.id}#activity/announce/${Date.now()}`, - type: 'Announce', - to: [`${nconf.get('url')}/category/${cid}/followers`], - cc: [activitypub._constants.publicAddress], - object, - }); + await Promise.all([req.body, object].map(async (object) => { + await activitypub.send('cid', cid, followers, { + id: `${object.id}#activity/announce/${Date.now()}`, + type: 'Announce', + to: [`${nconf.get('url')}/category/${cid}/followers`], + cc: [activitypub._constants.publicAddress], + object, + }); + })); } } }; diff --git a/src/api/activitypub.js b/src/api/activitypub.js index 154fe2aebc..5ca442fbd5 100644 --- a/src/api/activitypub.js +++ b/src/api/activitypub.js @@ -155,27 +155,16 @@ activitypubApi.create.note = enabledCheck(async (caller, { pid }) => { await activitypub.send('uid', caller.uid, Array.from(targets), payload); if (followers.length) { - // The 1b12 announce is just a wrapper around the same payload - const announce = { - id: `${object.id}#activity/announce/${Date.now()}`, - type: 'Announce', - to: [activitypub._constants.publicAddress], - cc: [`${nconf.get('url')}/category/${cid}/followers`], - object: payload, - }; - const implicit = { - id: `${object.id}#activity/announce/${Date.now()}`, - type: 'Announce', - to: [activitypub._constants.publicAddress], - cc: [`${nconf.get('url')}/category/${cid}/followers`], - object: payload.object, - }; - setTimeout(() => { // Delay sending to avoid potential race condition - Promise.all([ - activitypub.send('cid', cid, followers, announce), - activitypub.send('cid', cid, followers, implicit), - ]).catch(err => winston.error(err.stack)); + Promise.all([payload, payload.object].map(async (object) => { + await activitypub.send('cid', cid, followers, { + id: `${object.id}#activity/announce/${Date.now()}`, + type: 'Announce', + to: [activitypub._constants.publicAddress], + cc: [`${nconf.get('url')}/category/${cid}/followers`], + object, + }); + })).catch(err => winston.error(err.stack)); }, 5000); } });