aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulio Capote <jcapote@gmail.com>2023-01-05 02:45:19 +0000
committerJulio Capote <jcapote@gmail.com>2023-01-05 02:45:19 +0000
commitb66043eec7c78a00a72c19fd902ec1d11a5133cb (patch)
treef1cdd2d9da3a1b33cdc37940546f0fa50517b8cc
parente9124914cd6b05502cb5dd7f34720b27657560aa (diff)
downloadcommunique-b66043eec7c78a00a72c19fd902ec1d11a5133cb.tar.gz
format accept payload
-rw-r--r--registry/registry.go28
1 files changed, 27 insertions, 1 deletions
diff --git a/registry/registry.go b/registry/registry.go
index aca1db7..1c8c9b3 100644
--- a/registry/registry.go
+++ b/registry/registry.go
@@ -185,14 +185,24 @@ func (r *Registry) Inbox(name string, req *http.Request, payload []byte) error {
return err
}
- resolver, err := streams.NewJSONResolver(func(c context.Context, p vocab.ActivityStreamsFollow) error {
+ actorUrl, err := urls.UrlProfile(handler.handlerCfg.Name, r.cfg.Domain)
+ if err != nil {
+ return err
+ }
+
+ resolver, err := streams.NewJSONResolver(func(c context.Context, follow vocab.ActivityStreamsFollow) error {
+ // Follow
idProp := person.GetJSONLDId()
idPropUrl := idProp.Get()
inboxProp := person.GetActivityStreamsInbox()
url := inboxProp.GetIRI()
logger.With("actor", idPropUrl).With("inbox", url).Debugf("follow")
+
+ deliverAcceptToInbox(url, actorUrl, follow, handler.handlerCfg, r.log)
+ // subscribeActorToHandler()
return nil
}, func(c context.Context, note vocab.ActivityStreamsUndo) error {
+ // Unfollow
idProp := person.GetJSONLDId()
idPropUrl := idProp.Get()
inboxProp := person.GetActivityStreamsInbox()
@@ -202,6 +212,22 @@ func (r *Registry) Inbox(name string, req *http.Request, payload []byte) error {
})
err = resolver.Resolve(ctx, followData)
+ return err
+}
+
+func deliverAcceptToInbox(url, actorUrl *url.URL, follow vocab.ActivityStreamsFollow, handler config.Handler, log *zap.SugaredLogger) error {
+ accept := streams.NewActivityStreamsAccept()
+ actorProp := streams.NewActivityStreamsActorProperty()
+ actorProp.AppendIRI(actorUrl)
+ accept.SetActivityStreamsActor(actorProp)
+ objProp := streams.NewActivityStreamsObjectProperty()
+ objProp.AppendActivityStreamsFollow(follow)
+ accept.SetActivityStreamsObject(objProp)
+ payload, err := streams.Serialize(accept)
+ if err != nil {
+ return err
+ }
+ log.With("type", "delivery").With("payload", payload).Debugf("sending accept")
return nil
}