From e10fafa805fb4bfd852237e23b85ad8a778964af Mon Sep 17 00:00:00 2001 From: pancakes Date: Sun, 3 Nov 2024 12:19:33 +1000 Subject: [PATCH] [backend/masto-client] Add accounts/{id}/remove_from_followers --- .../Controllers/Mastodon/AccountController.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Iceshrimp.Backend/Controllers/Mastodon/AccountController.cs b/Iceshrimp.Backend/Controllers/Mastodon/AccountController.cs index 4fb273af..d617eb3c 100644 --- a/Iceshrimp.Backend/Controllers/Mastodon/AccountController.cs +++ b/Iceshrimp.Backend/Controllers/Mastodon/AccountController.cs @@ -244,6 +244,28 @@ public class AccountController( return RenderRelationship(followee); } + [HttpPost("{id}/remove_from_followers")] + [Authorize("write:follows")] + [ProducesResults(HttpStatusCode.OK)] + [ProducesErrors(HttpStatusCode.BadRequest)] + public async Task RemoveFromFollowers(string id) + { + var user = HttpContext.GetUserOrFail(); + if (user.Id == id) + throw GracefulException.BadRequest("You cannot unfollow yourself"); + + var follower = await db.Followings + .Where(p => p.FolloweeId == user.Id && p.FollowerId == id) + .Select(p => p.Follower) + .IncludeCommonProperties() + .PrecomputeRelationshipData(user) + .FirstOrDefaultAsync() ?? + throw GracefulException.RecordNotFound(); + + await userSvc.RemoveFromFollowersAsync(user, follower); + return RenderRelationship(follower); + } + [HttpPost("{id}/mute")] [Authorize("write:mutes")] [ProducesResults(HttpStatusCode.OK)]