feat: add id to follows and verify accepts

This commit is contained in:
Opliko
2024-04-09 23:58:52 +02:00
parent b921f8d167
commit 72dbcfe3d9
2 changed files with 14 additions and 6 deletions

View File

@@ -255,9 +255,15 @@ inbox.accept = async (req) => {
} }
if (type === 'Follow') { if (type === 'Follow') {
if (!await db.isSortedSetMember(`followRequests:${uid}`, actor)) {
throw new Error('[[error:activitypub.get-failed]]');
}
const now = Date.now(); const now = Date.now();
await db.sortedSetAdd(`followingRemote:${uid}`, now, actor); await Promise.all([
await db.sortedSetAdd(`followersRemote:${actor}`, now, uid); // for followers backreference and notes assertion checking 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}`); const followingRemoteCount = await db.sortedSetCard(`followingRemote:${uid}`);
await user.setUserField(uid, 'followingRemoteCount', followingRemoteCount); await user.setUserField(uid, 'followingRemoteCount', followingRemoteCount);
} }
@@ -351,7 +357,6 @@ inbox.undo = async (req) => {
} }
} }
}; };
inbox.flag = async (req) => { inbox.flag = async (req) => {
const { actor, object, content } = req.body; const { actor, object, content } = req.body;
const objects = Array.isArray(object) ? object : [object]; const objects = Array.isArray(object) ? object : [object];

View File

@@ -38,9 +38,12 @@ activitypubApi.follow = enabledCheck(async (caller, { uid } = {}) => {
} }
await activitypub.send('uid', caller.uid, [result.actorUri], { await activitypub.send('uid', caller.uid, [result.actorUri], {
id: `${nconf.get('url')}/uid/${caller.uid}#activity/follow/${result.username}@${result.hostname}`,
type: 'Follow', type: 'Follow',
object: result.actorUri, object: result.actorUri,
}); });
await db.sortedSetAdd(`followRequests:${caller.uid}`, Date.now(), result.actorUri);
}); });
// should be .undo.follow // should be .undo.follow
@@ -109,14 +112,14 @@ activitypubApi.create.post = enabledCheck(async (caller, { pid }) => {
const payloads = { const payloads = {
create: { create: {
id: `${object.id}#create`, id: `${object.id}#activity/create`,
type: 'Create', type: 'Create',
to: object.to, to: object.to,
cc: object.cc, cc: object.cc,
object, object,
}, },
announce: { announce: {
id: `${object.id}#announce`, id: `${object.id}#activity/announce`,
type: 'Announce', type: 'Announce',
to: [`${nconf.get('url')}/category/${cid}/followers`], to: [`${nconf.get('url')}/category/${cid}/followers`],
cc: [activitypub._constants.publicAddress], cc: [activitypub._constants.publicAddress],
@@ -157,7 +160,7 @@ activitypubApi.update.note = enabledCheck(async (caller, { post }) => {
} }
const payload = { const payload = {
id: `${object.id}#update/${post.edited}`, id: `${object.id}#activity/update/${post.edited}`,
type: 'Update', type: 'Update',
to: object.to, to: object.to,
cc: object.cc, cc: object.cc,