From e50e72af5bf533a9dc5449a13a08fa213dc20be8 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Wed, 12 Feb 2025 23:43:09 -0800 Subject: [PATCH] fix(ap): resolve issue where follows would not work if private mode was enabled. Fixes #4142 (#4202) --- activitypub/inbox/follow.go | 2 +- activitypub/persistence/persistence.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/activitypub/inbox/follow.go b/activitypub/inbox/follow.go index 6c4c3378b..21d0ecba1 100644 --- a/activitypub/inbox/follow.go +++ b/activitypub/inbox/follow.go @@ -47,7 +47,7 @@ func handleFollowInboxRequest(c context.Context, activity vocab.ActivityStreamsF } } - // Save as an accepted activity + // Save as an activity actorReference := activity.GetActivityStreamsActor() object := activity.GetActivityStreamsObject() objectIRI := object.At(0).GetIRI().String() diff --git a/activitypub/persistence/persistence.go b/activitypub/persistence/persistence.go index e83933e93..412782934 100644 --- a/activitypub/persistence/persistence.go +++ b/activitypub/persistence/persistence.go @@ -3,6 +3,7 @@ package persistence import ( "context" "database/sql" + "encoding/json" "fmt" "net/url" "time" @@ -74,6 +75,27 @@ func GetFollower(iri string) (*apmodels.ActivityPubActor, error) { return nil, errors.Wrap(err, "error parsing acting inbox") } + requestObjectBytes := result.RequestObject + var followRequestObject vocab.ActivityStreamsFollow + + resolver, err := streams.NewJSONResolver(func(c context.Context, followObject vocab.ActivityStreamsFollow) error { + followRequestObject = followObject + return nil + }) + if err != nil { + return nil, errors.Wrap(err, "error creating JSON resolver") + } + jsonMap := make(map[string]interface{}) + err = json.Unmarshal(requestObjectBytes, &jsonMap) + if err != nil { + return nil, errors.Wrap(err, "error unmarshaling follow request object") + } + + err = resolver.Resolve(context.Background(), jsonMap) + if err != nil { + return nil, errors.Wrap(err, "error resolving follow request object") + } + image, _ := url.Parse(result.Image.String) var disabledAt *time.Time @@ -89,6 +111,7 @@ func GetFollower(iri string) (*apmodels.ActivityPubActor, error) { Image: image, FollowRequestIri: followIRI, DisabledAt: disabledAt, + RequestObject: followRequestObject, } return &follower, nil