aboutsummaryrefslogtreecommitdiff
path: root/registry
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--registry/registry.go32
1 files changed, 22 insertions, 10 deletions
diff --git a/registry/registry.go b/registry/registry.go
index dc5dff2..e15d861 100644
--- a/registry/registry.go
+++ b/registry/registry.go
@@ -210,32 +210,44 @@ func (r *Registry) Inbox(name string, req *http.Request, payload []byte) error {
idProp := person.GetJSONLDId()
idPropUrl := idProp.Get()
inboxProp := person.GetActivityStreamsInbox()
- url := inboxProp.GetIRI()
- logger.With("actor", idPropUrl).With("inbox", url).Debugf("follow")
+ inboxUrl := inboxProp.GetIRI()
+ logger.With("actor", idPropUrl).With("inbox", inboxUrl).Debugf("follow")
actorKeyUrl, err := urls.UrlProfileKey(handler.handlerCfg.Name, r.cfg.Domain)
if err != nil {
return err
}
-
- r.deliverAcceptToInbox(url, actorUrl, actorKeyUrl, follow, handler.handlerCfg)
- // r.subscribeActorToHandler()
- return nil
+ err = r.deliverAcceptToInbox(inboxUrl, actorUrl, actorKeyUrl, follow, handler.handlerCfg)
+ if err != nil {
+ return err
+ }
+ return r.subscribeActorToHandler(handler.handlerCfg, inboxUrl.String())
}, func(c context.Context, note vocab.ActivityStreamsUndo) error {
// Unfollow
idProp := person.GetJSONLDId()
idPropUrl := idProp.Get()
inboxProp := person.GetActivityStreamsInbox()
- url := inboxProp.GetIRI()
- logger.With("actor", idPropUrl).With("inbox", url).Debugf("undo")
- // r.unsubscribeActorToHandler()
- return nil
+ inboxUrl := inboxProp.GetIRI()
+ logger.With("actor", idPropUrl).With("inbox", inboxUrl).Debugf("unfollow/undo")
+ return r.unsubscribeActorToHandler(handler.handlerCfg, inboxUrl.String())
})
err = resolver.Resolve(ctx, followData)
return err
}
+func (r *Registry) subscribeActorToHandler(handler config.Handler, inboxUrl string) error {
+ aso, err := models.CreateSubscription(handler, inboxUrl)
+ r.persister.Store(aso)
+ return err
+}
+
+func (r *Registry) unsubscribeActorToHandler(handler config.Handler, inboxUrl string) error {
+ aso, err := models.CreateSubscription(handler, inboxUrl)
+ r.persister.Delete(aso)
+ return err
+}
+// TODO should probably be in its own delivery package
func (r *Registry) deliverAcceptToInbox(url, actorUrl, actorKeyUrl *url.URL, follow vocab.ActivityStreamsFollow, handler config.Handler) error {
accept := streams.NewActivityStreamsAccept()
actorProp := streams.NewActivityStreamsActorProperty()