diff options
author | Julio Capote <jcapote@gmail.com> | 2023-01-05 02:45:19 +0000 |
---|---|---|
committer | Julio Capote <jcapote@gmail.com> | 2023-01-05 02:45:19 +0000 |
commit | b66043eec7c78a00a72c19fd902ec1d11a5133cb (patch) | |
tree | f1cdd2d9da3a1b33cdc37940546f0fa50517b8cc /registry | |
parent | e9124914cd6b05502cb5dd7f34720b27657560aa (diff) | |
download | communique-b66043eec7c78a00a72c19fd902ec1d11a5133cb.tar.gz |
format accept payload
Diffstat (limited to 'registry')
-rw-r--r-- | registry/registry.go | 28 |
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 } |