From 566b3bc4594bfbcb457a844fdd6163cbad2838c6 Mon Sep 17 00:00:00 2001 From: erik Date: Fri, 24 Nov 2023 12:49:36 +0100 Subject: [PATCH] Parse Actor from star activity, Update function declaration order --- models/activitypub/actor.go | 47 +++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/models/activitypub/actor.go b/models/activitypub/actor.go index 214c0478ea..79d4d1d671 100644 --- a/models/activitypub/actor.go +++ b/models/activitypub/actor.go @@ -18,33 +18,14 @@ type Validatable interface { // ToDo: What is the right package for this interfa } type ActorID struct { - schema string userId string + source forgefed.SourceType + schema string path string host string port string // optional } -func (a ActorID) GetUserId() int { - result, err := strconv.Atoi(a.userId) - - if err != nil { - panic(err) - } - - return result -} - -// Returns the combination of host:port if port exists, host otherwise -func (a ActorID) GetHostAndPort() string { - - if a.port != "" { - return strings.Join([]string{a.host, a.port}, ":") - } - - return a.host -} - // ToDo: validate_is_not_empty maybe not as an extra method func (a ActorID) validate_is_not_empty(str string, field string) error { @@ -99,8 +80,28 @@ func (a ActorID) PanicIfInvalid() { } } -func ParseActorID(actor string) (ActorID, error) { - u, err := url.Parse(actor) +func (a ActorID) GetUserId() int { + result, err := strconv.Atoi(a.userId) + + if err != nil { + panic(err) + } + + return result +} + +// Returns the combination of host:port if port exists, host otherwise +func (a ActorID) GetHostAndPort() string { + + if a.port != "" { + return strings.Join([]string{a.host, a.port}, ":") + } + + return a.host +} + +func ParseActorFromStarActivity(star *forgefed.Star) (ActorID, error) { + u, err := url.Parse(star.Actor.GetID().String()) // check if userID IRI is well formed url if err != nil {