From 42f514b7937dc2ffd82d505c62964362e8ec3dd8 Mon Sep 17 00:00:00 2001 From: Opliko Date: Tue, 11 Jun 2024 22:55:45 +0200 Subject: [PATCH] feat: add timestamp to most activity ids --- src/activitypub/helpers.js | 4 ++-- src/activitypub/inbox.js | 6 +++--- src/activitypub/notes.js | 2 +- src/api/activitypub.js | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/activitypub/helpers.js b/src/activitypub/helpers.js index 5eb51077b8..168a378f83 100644 --- a/src/activitypub/helpers.js +++ b/src/activitypub/helpers.js @@ -130,8 +130,8 @@ Helpers.resolveLocalId = async (input) => { let activityData = {}; if (hash.startsWith('#activity')) { - const [, activity, data] = hash.split('/', 3); - activityData = { activity, data }; + const [, activity, data, timestamp] = hash.split('/', 4); + activityData = { activity, data, timestamp }; } // https://bb.devnull.land/cid/2#activity/follow/activitypub@community.nodebb.org│ diff --git a/src/activitypub/inbox.js b/src/activitypub/inbox.js index 7d7172d082..f9ec123dac 100644 --- a/src/activitypub/inbox.js +++ b/src/activitypub/inbox.js @@ -48,7 +48,7 @@ inbox.create = async (req) => { const followers = await activitypub.notes.getCategoryFollowers(cid); if (followers.length) { await activitypub.send('cid', cid, followers, { - id: `${object.id}#activity/announce`, + id: `${object.id}#activity/announce/${Date.now()}`, type: 'Announce', to: [`${nconf.get('url')}/category/${cid}/followers`], cc: [activitypub._constants.publicAddress], @@ -281,7 +281,7 @@ inbox.follow = async (req) => { user.onFollow(actor, id); activitypub.send('uid', id, actor, { - id: `${nconf.get('url')}/${type}/${id}#activity/accept:follow/${handle}`, + id: `${nconf.get('url')}/${type}/${id}#activity/accept:follow/${handle}/${Date.now()}`, type: 'Accept', object: { id: followId, @@ -308,7 +308,7 @@ inbox.follow = async (req) => { } activitypub.send('cid', id, actor, { - id: `${nconf.get('url')}/${type}/${id}#activity/accept:follow/${handle}`, + id: `${nconf.get('url')}/${type}/${id}#activity/accept:follow/${handle}/${Date.now()}`, type: 'Accept', object: { id: followId, diff --git a/src/activitypub/notes.js b/src/activitypub/notes.js index f1fd7ce89b..da377b4c53 100644 --- a/src/activitypub/notes.js +++ b/src/activitypub/notes.js @@ -159,7 +159,7 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => { const followers = await activitypub.notes.getCategoryFollowers(cid); // eslint-disable-next-line no-await-in-loop await activitypub.send('cid', cid, followers, { - id: `${object.id}#activity/announce`, + id: `${object.id}#activity/announce/${Date.now()}`, type: 'Announce', to: [`${nconf.get('url')}/category/${cid}/followers`], cc: [activitypub._constants.publicAddress], diff --git a/src/api/activitypub.js b/src/api/activitypub.js index df374635e1..b95c58db00 100644 --- a/src/api/activitypub.js +++ b/src/api/activitypub.js @@ -70,7 +70,7 @@ activitypubApi.unfollow = enabledCheck(async (caller, { type, id, actor }) => { } await activitypub.send(type, id, [actor], { - id: `${nconf.get('url')}/${type}/${id}#activity/undo:follow/${handle}`, + id: `${nconf.get('url')}/${type}/${id}#activity/undo:follow/${handle}/${Date.now()}`, type: 'Undo', object, }); @@ -146,14 +146,14 @@ activitypubApi.create.note = enabledCheck(async (caller, { pid }) => { const payloads = { create: { - id: `${object.id}#activity/create`, + id: `${object.id}#activity/create/${Date.now()}`, type: 'Create', to, cc, object, }, announce: { - id: `${object.id}#activity/announce`, + id: `${object.id}#activity/announce/${Date.now()}`, type: 'Announce', to: [activitypub._constants.publicAddress], cc: [`${nconf.get('url')}/category/${cid}/followers`], @@ -277,7 +277,7 @@ activitypubApi.undo.like = enabledCheck(async (caller, { pid }) => { } await activitypub.send('uid', caller.uid, [uid], { - id: `${nconf.get('url')}/uid/${caller.uid}#activity/undo:like/${encodeURIComponent(pid)}`, + id: `${nconf.get('url')}/uid/${caller.uid}#activity/undo:like/${encodeURIComponent(pid)}/${Date.now()}`, type: 'Undo', object: { actor: `${nconf.get('url')}/uid/${caller.uid}`, @@ -318,7 +318,7 @@ activitypubApi.undo.flag = enabledCheck(async (caller, flag) => { const reason = flag.reason || (flag.reports && flag.reports.filter(report => report.reporter.uid === caller.uid).at(-1).value); await activitypub.send('uid', caller.uid, reportedIds, { - id: `${nconf.get('url')}/${flag.type}/${encodeURIComponent(flag.targetId)}#activity/undo:flag/${caller.uid}`, + id: `${nconf.get('url')}/${flag.type}/${encodeURIComponent(flag.targetId)}#activity/undo:flag/${caller.uid}/${Date.now()}`, type: 'Undo', object: { id: `${nconf.get('url')}/${flag.type}/${encodeURIComponent(flag.targetId)}#activity/flag/${caller.uid}`,