From ca18901fccc8dc887eb18aa07a9dda6beb010907 Mon Sep 17 00:00:00 2001 From: Cory Slep Date: Wed, 3 Apr 2019 23:35:57 +0200 Subject: [PATCH] Bugfix for programmatic delivery --- pub/actor.go | 8 +++---- pub/delegate_actor.go | 4 +++- pub/side_effect_actor.go | 50 +++++++++++++++++++++++----------------- 3 files changed, 36 insertions(+), 26 deletions(-) diff --git a/pub/actor.go b/pub/actor.go index 8fb1995..771601d 100644 --- a/pub/actor.go +++ b/pub/actor.go @@ -1,8 +1,8 @@ package pub import ( - "github.com/go-fed/activity/streams/vocab" "context" + "github.com/go-fed/activity/streams/vocab" "net/http" "net/url" ) @@ -102,9 +102,9 @@ type FederatingActor interface { // The provided url must be the outbox of the sender. All processing of // the activity occurs similarly to the C2S flow: // - If t is not an Activity, it is wrapped in a Create activity. - // - A new ID is generated for the activity - // - The activity is added to the specified outbox - // - The activity is prepared and delivered to recipients + // - A new ID is generated for the activity. + // - The activity is added to the specified outbox. + // - The activity is prepared and delivered to recipients. // // Note that this function will only behave as expected if the // implementation has been constructed to support federation. This diff --git a/pub/delegate_actor.go b/pub/delegate_actor.go index a1e4ae5..bce54bf 100644 --- a/pub/delegate_actor.go +++ b/pub/delegate_actor.go @@ -115,7 +115,9 @@ type DelegateActor interface { // PostOutbox delegates the logic for side effects and adding to the // outbox. // - // Only called if the Social API is enabled. + // Always called, regardless whether the Federated Protocol or Social + // API is enabled. In the case of the Social API being enabled, side + // effects of the Activity must occur. // // The delegate is responsible for adding the activity to the database's // general storage for independent retrieval, and not just within the diff --git a/pub/side_effect_actor.go b/pub/side_effect_actor.go index 3b9c68f..b1054c7 100644 --- a/pub/side_effect_actor.go +++ b/pub/side_effect_actor.go @@ -63,6 +63,10 @@ func (a *sideEffectActor) GetInbox(c context.Context, r *http.Request) (vocab.Ac func (a *sideEffectActor) AuthorizePostInbox(c context.Context, w http.ResponseWriter, activity Activity) (authorized bool, err error) { authorized = false actor := activity.GetActivityStreamsActor() + if actor == nil { + err = fmt.Errorf("no actors in post to inbox") + return + } var iris []*url.URL for i := 0; i < actor.Len(); i++ { iter := actor.At(i) @@ -299,30 +303,34 @@ func (a *sideEffectActor) InboxForwarding(c context.Context, inboxIRI *url.URL, // This implementation assumes all types are meant to be delivered except for // the ActivityStreams Block type. func (a *sideEffectActor) PostOutbox(c context.Context, activity Activity, outboxIRI *url.URL, rawJSON map[string]interface{}) (deliverable bool, err error) { - wrapped, other := a.c2s.Callbacks(c) - // Populate side channels. - wrapped.db = a.db - wrapped.outboxIRI = outboxIRI - wrapped.rawActivity = rawJSON - wrapped.clock = a.clock - wrapped.newTransport = a.common.NewTransport - undeliverable := false - wrapped.undeliverable = &undeliverable - var res *streams.TypeResolver - res, err = streams.NewTypeResolver(wrapped.callbacks(other)...) - if err != nil { - return - } - if err = res.Resolve(c, activity); err != nil && !streams.IsUnmatchedErr(err) { - return - } else if streams.IsUnmatchedErr(err) { - deliverable = true - err = a.c2s.DefaultCallback(c, activity) + // TODO: Determine this if c2s is nil + deliverable = true + if a.c2s != nil { + wrapped, other := a.c2s.Callbacks(c) + // Populate side channels. + wrapped.db = a.db + wrapped.outboxIRI = outboxIRI + wrapped.rawActivity = rawJSON + wrapped.clock = a.clock + wrapped.newTransport = a.common.NewTransport + undeliverable := false + wrapped.undeliverable = &undeliverable + var res *streams.TypeResolver + res, err = streams.NewTypeResolver(wrapped.callbacks(other)...) if err != nil { return } - } else { - deliverable = !undeliverable + if err = res.Resolve(c, activity); err != nil && !streams.IsUnmatchedErr(err) { + return + } else if streams.IsUnmatchedErr(err) { + deliverable = true + err = a.c2s.DefaultCallback(c, activity) + if err != nil { + return + } + } else { + deliverable = !undeliverable + } } err = a.addToOutbox(c, outboxIRI, activity) return