From 75062fca2ffcd5e6bfac9e77072ab6fd36066707 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Sat, 27 Jan 2024 03:04:11 +0100 Subject: [PATCH] Handle undo activity for follow requests --- .../ActivityPub/ActivityHandlerService.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Iceshrimp.Backend/Core/Federation/ActivityPub/ActivityHandlerService.cs b/Iceshrimp.Backend/Core/Federation/ActivityPub/ActivityHandlerService.cs index 399c2404..e6557ca1 100644 --- a/Iceshrimp.Backend/Core/Federation/ActivityPub/ActivityHandlerService.cs +++ b/Iceshrimp.Backend/Core/Federation/ActivityPub/ActivityHandlerService.cs @@ -27,18 +27,25 @@ public class ActivityHandlerService( switch (activity.Type) { case ASActivity.Types.Create: { + //TODO: implement the rest if (activity.Object is ASNote note) return noteSvc.ProcessNote(note, activity.Actor); - throw new NotImplementedException(); + throw GracefulException.UnprocessableEntity("Create activity object is invalid"); } case ASActivity.Types.Follow: { if (activity.Object is { } obj) return Follow(obj, activity.Actor, activity.Id); throw GracefulException.UnprocessableEntity("Follow activity object is invalid"); } - case ASActivity.Types.Unfollow: - case ASActivity.Types.Undo: { - if (activity.Object is { } obj) return Unfollow(obj, activity.Actor, activity.Id); + case ASActivity.Types.Unfollow: { + if (activity.Object is { } obj) return Unfollow(obj, activity.Actor); throw GracefulException.UnprocessableEntity("Unfollow activity object is invalid"); } + case ASActivity.Types.Undo: { + //TODO: implement the rest + //TODO: test if this actually works + if (activity.Object is ASActivity { Type: ASActivity.Types.Follow, Object: not null } undoActivity) + return Unfollow(undoActivity.Object, activity.Actor); + throw new NotImplementedException(); + } default: { throw new NotImplementedException(); } @@ -99,7 +106,7 @@ public class ActivityHandlerService( } } - private async Task Unfollow(ASObject followeeActor, ASObject followerActor, string id) { + private async Task Unfollow(ASObject followeeActor, ASObject followerActor) { var follower = await userResolver.Resolve(followerActor.Id); var followee = await userResolver.Resolve(followeeActor.Id);