From f50a36d5cc69c095ba4a5d4a3d240c5284e2b234 Mon Sep 17 00:00:00 2001 From: Julio Capote Date: Sun, 8 Jan 2023 08:47:54 -0500 Subject: summaries and only render if image exists --- views/actor.go | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'views/actor.go') diff --git a/views/actor.go b/views/actor.go index bc89f95..36f1f0c 100644 --- a/views/actor.go +++ b/views/actor.go @@ -1,13 +1,11 @@ package views import ( - "fmt" - "git.capotej.com/capotej/communique/urls" "github.com/go-fed/activity/streams" ) -func RenderActor(name, domain, pem, mediaType string) (map[string]interface{}, error) { +func RenderActor(name, domain, pem, mediaType, summary string) (map[string]interface{}, error) { inbox, err := urls.UrlInbox(name, domain) if err != nil { return nil, err @@ -56,17 +54,19 @@ func RenderActor(name, domain, pem, mediaType string) (map[string]interface{}, e p.SetActivityStreamsInbox(inboxProp) p.SetActivityStreamsOutbox(outboxProp) - image := streams.NewActivityStreamsImage() - mediaTypeProp := streams.NewActivityStreamsMediaTypeProperty() - mediaTypeProp.Set(mediaType) - image.SetActivityStreamsMediaType(mediaTypeProp) - urlProp := streams.NewActivityStreamsUrlProperty() - urlProp.AppendIRI(actorAvatarUrl) - image.SetActivityStreamsUrl(urlProp) - - iconProp := streams.NewActivityStreamsIconProperty() - iconProp.AppendActivityStreamsImage(image) - p.SetActivityStreamsIcon(iconProp) + if mediaType != "" { + image := streams.NewActivityStreamsImage() + mediaTypeProp := streams.NewActivityStreamsMediaTypeProperty() + mediaTypeProp.Set(mediaType) + image.SetActivityStreamsMediaType(mediaTypeProp) + urlProp := streams.NewActivityStreamsUrlProperty() + urlProp.AppendIRI(actorAvatarUrl) + image.SetActivityStreamsUrl(urlProp) + + iconProp := streams.NewActivityStreamsIconProperty() + iconProp.AppendActivityStreamsImage(image) + p.SetActivityStreamsIcon(iconProp) + } nameProp := streams.NewActivityStreamsNameProperty() nameProp.AppendXMLSchemaString(name) @@ -76,12 +76,16 @@ func RenderActor(name, domain, pem, mediaType string) (map[string]interface{}, e usernameProp.SetXMLSchemaString(name) p.SetActivityStreamsPreferredUsername(usernameProp) - urlProp = streams.NewActivityStreamsUrlProperty() - urlProp.AppendIRI(actorUrl) - p.SetActivityStreamsUrl(urlProp) + actorUrlProp := streams.NewActivityStreamsUrlProperty() + actorUrlProp.AppendIRI(actorUrl) + p.SetActivityStreamsUrl(actorUrlProp) summaryProp := streams.NewActivityStreamsSummaryProperty() - summaryProp.AppendXMLSchemaString(fmt.Sprintf("profile for %s", name)) + if summary != "" { + summaryProp.AppendXMLSchemaString(summary) + } else { + summaryProp.AppendXMLSchemaString("an activitypub bot on communique (https://git.capotej.com/capotej/communique)") + } p.SetActivityStreamsSummary(summaryProp) followersProp := streams.NewActivityStreamsFollowersProperty() -- cgit v1.2.3