mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-11-22 09:54:24 +01:00
Implement NewForgeLike
This commit is contained in:
parent
2e0584bdf3
commit
ed256ca540
|
@ -6,6 +6,7 @@ package forgefed
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/validation"
|
"code.gitea.io/gitea/modules/validation"
|
||||||
|
|
||||||
ap "github.com/go-ap/activitypub"
|
ap "github.com/go-ap/activitypub"
|
||||||
|
@ -18,6 +19,21 @@ type ForgeLike struct {
|
||||||
ap.Activity
|
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) {
|
func (like ForgeLike) MarshalJSON() ([]byte, error) {
|
||||||
return like.Activity.MarshalJSON()
|
return like.Activity.MarshalJSON()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue