mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-10 12:49:52 +01:00
Implement NewForgeLike
This commit is contained in:
parent
2e0584bdf3
commit
ed256ca540
1 changed files with 16 additions and 0 deletions
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue