From b66043eec7c78a00a72c19fd902ec1d11a5133cb Mon Sep 17 00:00:00 2001 From: Julio Capote Date: Wed, 4 Jan 2023 21:45:19 -0500 Subject: format accept payload --- registry/registry.go | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) 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 } -- cgit v1.2.3