aboutsummaryrefslogtreecommitdiff
path: root/registry/registry.go
diff options
context:
space:
mode:
Diffstat (limited to 'registry/registry.go')
-rw-r--r--registry/registry.go41
1 files changed, 24 insertions, 17 deletions
diff --git a/registry/registry.go b/registry/registry.go
index a24d2d7..451704e 100644
--- a/registry/registry.go
+++ b/registry/registry.go
@@ -3,7 +3,8 @@ package registry
import (
"bytes"
"encoding/gob"
- "fmt"
+ "net/url"
+ "strings"
"git.capotej.com/capotej/communique/config"
"git.capotej.com/capotej/communique/models"
@@ -26,7 +27,7 @@ func NewRegistry(cfg config.Config, persister *models.Persister) *Registry {
reg := Registry{cfg: cfg, persister: persister}
reg.handlerMap = make(map[string]Handler)
for _, v := range cfg.Handlers {
- reg.handlerMap[fqn(v.Name, cfg.Domain)] = Handler{handlerCfg: v}
+ reg.handlerMap[v.Name] = Handler{handlerCfg: v}
}
return &reg
}
@@ -148,29 +149,35 @@ func (r *Registry) ActivityOrNote(activityOrNote, name, id string) (map[string]i
return views.RenderNote(handler.handlerCfg.Name, r.cfg.Domain, outboxItem)
}
-func (r *Registry) WebfingerResource(fqn string) (*views.WebfingerResource, error) {
- handler := r.findByFQN(fqn)
- if handler == nil {
- handler = r.findByFQN("acct:" + fqn)
+// This has to handle various lookup formats:
+// ?resource=acct:actor@domain
+// ?resource=actor@domain
+// ?resource=actor
+// ?resource=acct:actor
+func (r *Registry) Webfinger(fqn string) (*views.WebfingerResource, error) {
+ // Strip away acct: prefix, if found
+ fqn = strings.TrimPrefix(fqn, "acct:")
+
+ // Strip away @domain suffix, if found
+ domainUrl, err := url.Parse(r.cfg.Domain)
+ if err != nil {
+ return nil, err
}
+ hostname := "@" + domainUrl.Hostname()
+ fqn = strings.TrimSuffix(fqn, hostname)
+
+ // We should just have $actor left
+ handler := r.findByName(fqn)
if handler == nil {
return nil, nil
}
- return views.RenderWebfingerResource(handler.handlerCfg.Name, r.cfg.Domain)
+ return views.RenderWebfinger(handler.handlerCfg.Name, r.cfg.Domain, hostname)
}
-func fqn(name, domain string) string {
- return fmt.Sprintf("acct:%s@%s", name, domain)
-}
-
-func (r *Registry) findByFQN(fqn string) *Handler {
- handler, ok := r.handlerMap[fqn]
+func (r *Registry) findByName(name string) *Handler {
+ handler, ok := r.handlerMap[name]
if !ok {
return nil
}
return &handler
}
-
-func (r *Registry) findByName(name string) *Handler {
- return r.findByFQN(fqn(name, r.cfg.Domain))
-}