From 91a081a2bc16540c37ac76a719ab4dd79608ed5d Mon Sep 17 00:00:00 2001 From: Julio Capote Date: Mon, 2 Jan 2023 09:08:11 -0500 Subject: rename profile to actor --- http/router.go | 2 +- registry/registry.go | 4 +-- views/actor.go | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ views/profile.go | 74 ---------------------------------------------------- 4 files changed, 77 insertions(+), 77 deletions(-) create mode 100644 views/actor.go delete mode 100644 views/profile.go diff --git a/http/router.go b/http/router.go index 23843c4..f763c79 100644 --- a/http/router.go +++ b/http/router.go @@ -49,7 +49,7 @@ func (s *Router) Start(zapWriter io.Writer) { // "User" endpoint router.GET("/actors/:actor", func(c *gin.Context) { actorParam := c.Param("actor") - resource, err := s.registry.Profile(actorParam) + resource, err := s.registry.Actor(actorParam) render(c, resource, err) }) diff --git a/registry/registry.go b/registry/registry.go index 21f4622..a24d2d7 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -31,12 +31,12 @@ func NewRegistry(cfg config.Config, persister *models.Persister) *Registry { return ® } -func (r *Registry) Profile(name string) (map[string]interface{}, error) { +func (r *Registry) Actor(name string) (map[string]interface{}, error) { handler := r.findByName(name) if handler == nil { return nil, nil } - return views.RenderProfile(handler.handlerCfg.Name, r.cfg.Domain) + return views.RenderActor(handler.handlerCfg.Name, r.cfg.Domain) } func (r *Registry) Outbox(name string) (map[string]interface{}, error) { diff --git a/views/actor.go b/views/actor.go new file mode 100644 index 0000000..a91044a --- /dev/null +++ b/views/actor.go @@ -0,0 +1,74 @@ +package views + +import ( + "fmt" + + "git.capotej.com/capotej/communique/urls" + "github.com/go-fed/activity/streams" +) + +func RenderActor(name, domain string) (map[string]interface{}, error) { + inbox, err := urls.UrlInbox(name, domain) + if err != nil { + return nil, err + } + + inboxProp := streams.NewActivityStreamsInboxProperty() + inboxProp.SetIRI(inbox) + + outbox, err := urls.UrlOutbox(name, domain) + if err != nil { + return nil, err + } + + outboxProp := streams.NewActivityStreamsOutboxProperty() + outboxProp.SetIRI(outbox) + + actorUrl, err := urls.UrlProfile(name, domain) + if err != nil { + return nil, err + } + + followingUrl, err := urls.UrlFollowing(name, domain) + if err != nil { + return nil, err + } + + followersUrl, err := urls.UrlFollowers(name, domain) + if err != nil { + return nil, err + } + + p := streams.NewActivityStreamsService() + idProp := streams.NewJSONLDIdProperty() + idProp.Set(actorUrl) + p.SetJSONLDId(idProp) + p.SetActivityStreamsInbox(inboxProp) + p.SetActivityStreamsOutbox(outboxProp) + + nameProp := streams.NewActivityStreamsNameProperty() + nameProp.AppendXMLSchemaString(name) + p.SetActivityStreamsName(nameProp) + + usernameProp := streams.NewActivityStreamsPreferredUsernameProperty() + usernameProp.SetXMLSchemaString(name) + p.SetActivityStreamsPreferredUsername(usernameProp) + + urlProp := streams.NewActivityStreamsUrlProperty() + urlProp.AppendIRI(actorUrl) + p.SetActivityStreamsUrl(urlProp) + + summaryProp := streams.NewActivityStreamsSummaryProperty() + summaryProp.AppendXMLSchemaString(fmt.Sprintf("profile for %s", name)) + p.SetActivityStreamsSummary(summaryProp) + + followersProp := streams.NewActivityStreamsFollowersProperty() + followersProp.SetIRI(followersUrl) + p.SetActivityStreamsFollowers(followersProp) + + followingProp := streams.NewActivityStreamsFollowingProperty() + followingProp.SetIRI(followingUrl) + p.SetActivityStreamsFollowing(followingProp) + + return streams.Serialize(p) +} diff --git a/views/profile.go b/views/profile.go deleted file mode 100644 index 5b82b46..0000000 --- a/views/profile.go +++ /dev/null @@ -1,74 +0,0 @@ -package views - -import ( - "fmt" - - "git.capotej.com/capotej/communique/urls" - "github.com/go-fed/activity/streams" -) - -func RenderProfile(name, domain string) (map[string]interface{}, error) { - inbox, err := urls.UrlInbox(name, domain) - if err != nil { - return nil, err - } - - inboxProp := streams.NewActivityStreamsInboxProperty() - inboxProp.SetIRI(inbox) - - outbox, err := urls.UrlOutbox(name, domain) - if err != nil { - return nil, err - } - - outboxProp := streams.NewActivityStreamsOutboxProperty() - outboxProp.SetIRI(outbox) - - actorUrl, err := urls.UrlProfile(name, domain) - if err != nil { - return nil, err - } - - followingUrl, err := urls.UrlFollowing(name, domain) - if err != nil { - return nil, err - } - - followersUrl, err := urls.UrlFollowers(name, domain) - if err != nil { - return nil, err - } - - p := streams.NewActivityStreamsService() - idProp := streams.NewJSONLDIdProperty() - idProp.Set(actorUrl) - p.SetJSONLDId(idProp) - p.SetActivityStreamsInbox(inboxProp) - p.SetActivityStreamsOutbox(outboxProp) - - nameProp := streams.NewActivityStreamsNameProperty() - nameProp.AppendXMLSchemaString(name) - p.SetActivityStreamsName(nameProp) - - usernameProp := streams.NewActivityStreamsPreferredUsernameProperty() - usernameProp.SetXMLSchemaString(name) - p.SetActivityStreamsPreferredUsername(usernameProp) - - urlProp := streams.NewActivityStreamsUrlProperty() - urlProp.AppendIRI(actorUrl) - p.SetActivityStreamsUrl(urlProp) - - summaryProp := streams.NewActivityStreamsSummaryProperty() - summaryProp.AppendXMLSchemaString(fmt.Sprintf("profile for %s", name)) - p.SetActivityStreamsSummary(summaryProp) - - followersProp := streams.NewActivityStreamsFollowersProperty() - followersProp.SetIRI(followersUrl) - p.SetActivityStreamsFollowers(followersProp) - - followingProp := streams.NewActivityStreamsFollowingProperty() - followingProp.SetIRI(followingUrl) - p.SetActivityStreamsFollowing(followingProp) - - return streams.Serialize(p) -} -- cgit v1.2.3