From fe871bf130a2d32345175c454fdb2dc17314e476 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Fri, 9 Feb 2024 10:50:42 +0100 Subject: [PATCH] [backend/federation] Handle activities based on derived activity type instead of their type property --- .../ActivityPub/ActivityHandlerService.cs | 14 +++++++------- .../Federation/ActivityPub/ActivityRenderer.cs | 5 ++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Iceshrimp.Backend/Core/Federation/ActivityPub/ActivityHandlerService.cs b/Iceshrimp.Backend/Core/Federation/ActivityPub/ActivityHandlerService.cs index 022f6efb..5ac12cd1 100644 --- a/Iceshrimp.Backend/Core/Federation/ActivityPub/ActivityHandlerService.cs +++ b/Iceshrimp.Backend/Core/Federation/ActivityPub/ActivityHandlerService.cs @@ -31,39 +31,39 @@ public class ActivityHandlerService( //TODO: validate inboxUserId - switch (activity.Type) { - case ASActivity.Types.Create: { + switch (activity) { + case ASCreate: { //TODO: implement the rest if (activity.Object is not ASNote note) throw GracefulException.UnprocessableEntity("Create activity object is invalid"); await noteSvc.ProcessNoteAsync(note, activity.Actor); return; } - case ASActivity.Types.Follow: { + case ASFollow: { if (activity.Object is not { } obj) throw GracefulException.UnprocessableEntity("Follow activity object is invalid"); await FollowAsync(obj, activity.Actor, activity.Id); return; } - case ASActivity.Types.Unfollow: { + case ASUnfollow: { if (activity.Object is not { } obj) throw GracefulException.UnprocessableEntity("Unfollow activity object is invalid"); await UnfollowAsync(obj, activity.Actor); return; } - case ASActivity.Types.Accept: { + case ASAccept: { if (activity.Object is not { } obj) throw GracefulException.UnprocessableEntity("Accept activity object is invalid"); await AcceptAsync(obj, activity.Actor); return; } - case ASActivity.Types.Reject: { + case ASReject: { if (activity.Object is not { } obj) throw GracefulException.UnprocessableEntity("Reject activity object is invalid"); await RejectAsync(obj, activity.Actor); return; } - case ASActivity.Types.Undo: { + case ASUndo: { //TODO: implement the rest if (activity.Object is not ASActivity { Type: ASActivity.Types.Follow, Object: not null } undoActivity) throw new NotImplementedException("Unsupported undo operation"); diff --git a/Iceshrimp.Backend/Core/Federation/ActivityPub/ActivityRenderer.cs b/Iceshrimp.Backend/Core/Federation/ActivityPub/ActivityRenderer.cs index 433131ef..5685f65f 100644 --- a/Iceshrimp.Backend/Core/Federation/ActivityPub/ActivityRenderer.cs +++ b/Iceshrimp.Backend/Core/Federation/ActivityPub/ActivityRenderer.cs @@ -11,10 +11,9 @@ public class ActivityRenderer(IOptions config, UserRende private string GenerateActivityId() => $"https://{config.Value.WebDomain}/activities/{Guid.NewGuid().ToString().ToLowerInvariant()}"; - public static ASActivity RenderCreate(ASObject obj, ASObject actor) { - return new ASActivity { + public static ASCreate RenderCreate(ASObject obj, ASObject actor) { + return new ASCreate { Id = $"{obj.Id}#Create", - Type = ASActivity.Types.Create, Actor = new ASActor { Id = actor.Id }, Object = obj };