From ed256ca540456a577ee40a76c8536e2acbae14f6 Mon Sep 17 00:00:00 2001 From: erik Date: Thu, 21 Mar 2024 16:27:08 +0100 Subject: [PATCH] Implement NewForgeLike --- models/forgefed/activity.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/models/forgefed/activity.go b/models/forgefed/activity.go index 4016b71b38..b0d17b9a9c 100644 --- a/models/forgefed/activity.go +++ b/models/forgefed/activity.go @@ -6,6 +6,7 @@ package forgefed import ( "time" + "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/validation" ap "github.com/go-ap/activitypub" @@ -18,6 +19,21 @@ type ForgeLike struct { ap.Activity } +func NewForgeLike(ctx *context.APIContext) (ForgeLike, error) { + result := ForgeLike{} + actorIRI := ctx.Repo.Owner.APAPIURL() + objectIRI := ctx.Repo.Repository.APAPIURL() + result.Type = ap.LikeType + // ToDo: Would validating the source by Actor.Type field make sense? + result.Actor = ap.ActorNew(ap.IRI(actorIRI), "ForgejoUser") // Thats us, a User + result.Object = ap.ObjectNew(ap.ActivityVocabularyType(objectIRI)) // Thats them, a Repository + result.StartTime = time.Now() + if valid, err := validation.IsValid(result); !valid { + return ForgeLike{}, err + } + return result, nil +} + func (like ForgeLike) MarshalJSON() ([]byte, error) { return like.Activity.MarshalJSON() }