From 820d05c99737efc47af3eca75d185f22fb41645d Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Tue, 9 Apr 2024 21:24:23 -1000 Subject: [PATCH] Add FollowAccept handling --- server/api/users/[uuid]/inbox/index.ts | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/server/api/users/[uuid]/inbox/index.ts b/server/api/users/[uuid]/inbox/index.ts index 7e1a7c12..4014dc78 100644 --- a/server/api/users/[uuid]/inbox/index.ts +++ b/server/api/users/[uuid]/inbox/index.ts @@ -212,6 +212,34 @@ export default apiRoute(async (req, matchedRoute, extraData) => { return response("Follow request sent", 200); } + case "FollowAccept": { + const followAccept = body as Lysand.FollowAccept; + + const account = await resolveUser(followAccept.author); + + if (!account) { + return errorResponse("Author not found", 400); + } + + const relationship = await getRelationshipToOtherUser( + user, + account, + ); + + if (!relationship.requested) { + return response("There is no follow request to accept", 200); + } + + await client.relationship.update({ + where: { id: relationship.id }, + data: { + following: true, + requested: false, + }, + }); + + return response("Follow request accepted", 200); + } default: { return errorResponse("Unknown object type", 400); }