diff --git a/src/activitypub/inbox.js b/src/activitypub/inbox.js index 33a6f6f83b..d2c117fd44 100644 --- a/src/activitypub/inbox.js +++ b/src/activitypub/inbox.js @@ -376,11 +376,11 @@ inbox.accept = async (req) => { if (await db.isSortedSetMember(`followingRemote:${id}`, actor)) return; // already following return reject('Accept', req.body, actor); // not following, not requested, so reject to hopefully stop retries } - const now = Date.now(); + const timestamp = await db.sortedSetScore(`followRequests:uid.${id}`, actor); await Promise.all([ db.sortedSetRemove(`followRequests:uid.${id}`, actor), - db.sortedSetAdd(`followingRemote:${id}`, now, actor), - db.sortedSetAdd(`followersRemote:${actor}`, now, id), // for followers backreference and notes assertion checking + db.sortedSetAdd(`followingRemote:${id}`, timestamp, actor), + db.sortedSetAdd(`followersRemote:${actor}`, timestamp, id), // for followers backreference and notes assertion checking ]); const followingRemoteCount = await db.sortedSetCard(`followingRemote:${id}`); await user.setUserField(id, 'followingRemoteCount', followingRemoteCount); @@ -389,11 +389,11 @@ inbox.accept = async (req) => { if (await db.isSortedSetMember(`cid:${id}:following`, actor)) return; // already following return reject('Accept', req.body, actor); // not following, not requested, so reject to hopefully stop retries } - const now = Date.now(); + const timestamp = await db.sortedSetScore(`followRequests:cid.${id}`, actor); await Promise.all([ db.sortedSetRemove(`followRequests:cid.${id}`, actor), - db.sortedSetAdd(`cid:${id}:following`, now, actor), - db.sortedSetAdd(`followersRemote:${actor}`, now, `cid|${id}`), // for notes assertion checking + db.sortedSetAdd(`cid:${id}:following`, timestamp, actor), + db.sortedSetAdd(`followersRemote:${actor}`, timestamp, `cid|${id}`), // for notes assertion checking ]); } } diff --git a/src/api/activitypub.js b/src/api/activitypub.js index 0008dc82f8..a7362056db 100644 --- a/src/api/activitypub.js +++ b/src/api/activitypub.js @@ -42,14 +42,15 @@ activitypubApi.follow = enabledCheck(async (caller, { type, id, actor } = {}) => actor = actor.includes('@') ? await user.getUidByUserslug(actor) : actor; const handle = await user.getUserField(actor, 'username'); + const timestamp = Date.now(); await activitypub.send(type, id, [actor], { - id: `${nconf.get('url')}/${type}/${id}#activity/follow/${handle}/${Date.now()}`, + id: `${nconf.get('url')}/${type}/${id}#activity/follow/${handle}/${timestamp}`, type: 'Follow', object: actor, }); - await db.sortedSetAdd(`followRequests:${type}.${id}`, Date.now(), actor); + await db.sortedSetAdd(`followRequests:${type}.${id}`, timestamp, actor); }); // should be .undo.follow @@ -61,9 +62,14 @@ activitypubApi.unfollow = enabledCheck(async (caller, { type, id, actor }) => { actor = actor.includes('@') ? await user.getUidByUserslug(actor) : actor; const handle = await user.getUserField(actor, 'username'); + const timestamps = await db.sortedSetsScore([ + `followRequests:${type}.${id}`, + type === 'uid' ? `followingRemote:${id}` : `cid:${id}:following`, + ], actor); + const timestamp = timestamps[0] || timestamps[1]; const object = { - id: `${nconf.get('url')}/${type}/${id}#activity/follow/${handle}`, + id: `${nconf.get('url')}/${type}/${id}#activity/follow/${handle}/${timestamp}`, type: 'Follow', object: actor, }; @@ -74,7 +80,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}/${Date.now()}`, + id: `${nconf.get('url')}/${type}/${id}#activity/undo:follow/${handle}/${timestamp}`, type: 'Undo', object, });