aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulio Capote <jcapote@gmail.com>2023-01-08 13:47:54 +0000
committerJulio Capote <jcapote@gmail.com>2023-01-08 13:47:54 +0000
commitf50a36d5cc69c095ba4a5d4a3d240c5284e2b234 (patch)
treeddb4bb323a1d9a5c6d8c068b7571167112a4c6bc
parent9470ad27f2c725ceeaa6ca8c727670d59fdb5588 (diff)
downloadcommunique-f50a36d5cc69c095ba4a5d4a3d240c5284e2b234.tar.gz
summaries and only render if image exists
-rw-r--r--config/config.go1
-rw-r--r--registry/registry.go2
-rw-r--r--sample-config.toml3
-rw-r--r--views/actor.go40
4 files changed, 25 insertions, 21 deletions
diff --git a/config/config.go b/config/config.go
index e92b725..4c23ba1 100644
--- a/config/config.go
+++ b/config/config.go
@@ -14,6 +14,7 @@ type Handler struct {
AvatarContentType string
Exec string
Rpc string
+ Summary string
DedupWindow time.Duration
Interval time.Duration
}
diff --git a/registry/registry.go b/registry/registry.go
index e50c6a5..d5f8bd6 100644
--- a/registry/registry.go
+++ b/registry/registry.go
@@ -126,7 +126,7 @@ func (r *Registry) Actor(name string) (map[string]interface{}, error) {
Bytes: x509.MarshalPKCS1PublicKey(&privKey.PublicKey),
},
)
- return views.RenderActor(handler.handlerCfg.Name, r.cfg.Domain, string(pemdata), handler.handlerCfg.AvatarContentType)
+ return views.RenderActor(handler.handlerCfg.Name, r.cfg.Domain, string(pemdata), handler.handlerCfg.AvatarContentType, handler.handlerCfg.Summary)
}
func (r *Registry) ActorAvatar(name string) ([]byte, string, error) {
diff --git a/sample-config.toml b/sample-config.toml
index d724689..fc7bee3 100644
--- a/sample-config.toml
+++ b/sample-config.toml
@@ -5,8 +5,7 @@ dbPath = "bub.db"
name = "sample"
rpc = "cgi" # rename to protocol?
exec = "sample-cgi-handler.sh"
-avatarUrl = "https://loremflickr.com/320/240/dog"
-avatarContentType = "image/jpeg"
+summary = "sample bot"
interval = "1h"
dedupWindow = "5h"
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()