Skip to content

Node.js based forum software built for the modern web

feat: add id to follows and verify accepts

Opliko72dbcfe3d9f1
diff --git a/src/activitypub/inbox.js b/src/activitypub/inbox.js
index ed8d683e81..1ccf4adbd7 100644
--- a/src/activitypub/inbox.js
+++ b/src/activitypub/inbox.js
@@ -255,9 +255,15 @@ inbox.accept = async (req) => {
}
if (type === 'Follow') {
+ if (!await db.isSortedSetMember(`followRequests:${uid}`, actor)) {
+ throw new Error('[[error:activitypub.get-failed]]');
+ }
const now = Date.now();
- await db.sortedSetAdd(`followingRemote:${uid}`, now, actor);
- await db.sortedSetAdd(`followersRemote:${actor}`, now, uid); // for followers backreference and notes assertion checking
+ await Promise.all([
+ db.sortedSetRemove(`followRequests:${uid}`, actor),
+ db.sortedSetAdd(`followingRemote:${uid}`, now, actor),
+ db.sortedSetAdd(`followersRemote:${actor}`, now, uid), // for followers backreference and notes assertion checking
+ ]);
const followingRemoteCount = await db.sortedSetCard(`followingRemote:${uid}`);
await user.setUserField(uid, 'followingRemoteCount', followingRemoteCount);
}
@@ -351,7 +357,6 @@ inbox.undo = async (req) => {
}
}
};
-
inbox.flag = async (req) => {
const { actor, object, content } = req.body;
const objects = Array.isArray(object) ? object : [object];
diff --git a/src/api/activitypub.js b/src/api/activitypub.js
index 9bddb5db92..a36f40a337 100644
--- a/src/api/activitypub.js
+++ b/src/api/activitypub.js
@@ -38,9 +38,12 @@ activitypubApi.follow = enabledCheck(async (caller, { uid } = {}) => {
}
await activitypub.send('uid', caller.uid, [result.actorUri], {
+ id: `${nconf.get('url')}/uid/${caller.uid}#activity/follow/${result.username}@${result.hostname}`,
type: 'Follow',
object: result.actorUri,
});
+
+ await db.sortedSetAdd(`followRequests:${caller.uid}`, Date.now(), result.actorUri);
});
// should be .undo.follow
@@ -109,14 +112,14 @@ activitypubApi.create.post = enabledCheck(async (caller, { pid }) => {
const payloads = {
create: {
- id: `${object.id}#create`,
+ id: `${object.id}#activity/create`,
type: 'Create',
to: object.to,
cc: object.cc,
object,
},
announce: {
- id: `${object.id}#announce`,
+ id: `${object.id}#activity/announce`,
type: 'Announce',
to: [`${nconf.get('url')}/category/${cid}/followers`],
cc: [activitypub._constants.publicAddress],
@@ -157,7 +160,7 @@ activitypubApi.update.note = enabledCheck(async (caller, { post }) => {
}
const payload = {
- id: `${object.id}#update/${post.edited}`,
+ id: `${object.id}#activity/update/${post.edited}`,
type: 'Update',
to: object.to,
cc: object.cc,