[backend/federation] Handle activities based on derived activity type instead of their type property

This commit is contained in:
Laura Hausmann 2024-02-09 10:50:42 +01:00
parent 23e7630ca6
commit fe871bf130
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 9 additions and 10 deletions

View file

@ -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");

View file

@ -11,10 +11,9 @@ public class ActivityRenderer(IOptions<Config.InstanceSection> 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
};