diff options
Diffstat (limited to 'registry/registry.go')
-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 } |