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() }