Implement NewForgeLike

This commit is contained in:
erik 2024-03-21 16:27:08 +01:00
parent 2e0584bdf3
commit ed256ca540

View file

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