diff options
author | FChannel <> | 2022-05-22 13:02:48 -0700 |
---|---|---|
committer | FChannel <> | 2022-06-19 12:53:29 -0700 |
commit | 6a0f664b565716ad08301e7699d6c0393dbba977 (patch) | |
tree | f760adc388604486b9660682c629f44e6db61694 /routes/actor.go | |
parent | 580dec5b89215310ce34341e11ff17fe38bdb63a (diff) |
following pass through
Diffstat (limited to 'routes/actor.go')
-rw-r--r-- | routes/actor.go | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/routes/actor.go b/routes/actor.go index 0200d93..4f848f1 100644 --- a/routes/actor.go +++ b/routes/actor.go @@ -105,9 +105,10 @@ func ActorInbox(ctx *fiber.Ctx) error { case "Follow": for _, e := range activity.To { - if res, err := activitypub.GetActorFromDB(e); err == nil && res.Id != "" { + if _, err := activitypub.GetActorFromDB(e); err == nil { response := activity.AcceptFollow() response, err := response.SetActorFollower() + if err != nil { return util.MakeError(err, "ActorInbox") } @@ -116,52 +117,47 @@ func ActorInbox(ctx *fiber.Ctx) error { return util.MakeError(err, "ActorInbox") } - alreadyFollow := false - alreadyFollowing := false - autoSub, err := response.Actor.GetAutoSubscribe() - if err != nil { - return util.MakeError(err, "ActorInbox") - } + alreadyFollowing, err := response.Actor.IsAlreadyFollowing(response.Object.Id) - following, err := response.Actor.GetFollowing() if err != nil { return util.MakeError(err, "ActorInbox") } - for _, e := range following { - if e.Id == response.Object.Id { - alreadyFollow = true - } - } + objActor, err := activitypub.FingerActor(response.Object.Actor) - actor, err := activitypub.FingerActor(response.Object.Actor) - if err != nil { + if err != nil || objActor.Id == "" { return util.MakeError(err, "ActorInbox") } - reqActivity := activitypub.Activity{Id: actor.Following} + reqActivity := activitypub.Activity{Id: objActor.Following} remoteActorFollowingCol, err := reqActivity.GetCollection() + if err != nil { return util.MakeError(err, "ActorInbox") } + alreadyFollow := false + for _, e := range remoteActorFollowingCol.Items { if e.Id == response.Actor.Id { alreadyFollowing = true } } + autoSub, err := response.Actor.GetAutoSubscribe() + + if err != nil { + return util.MakeError(err, "ActorInbox") + } + if autoSub && !alreadyFollow && alreadyFollowing { followActivity, err := response.Actor.MakeFollowActivity(response.Object.Actor) + if err != nil { return util.MakeError(err, "ActorInbox") } - if res, err := activitypub.FingerActor(response.Object.Actor); err == nil && res.Id != "" { - if err := followActivity.MakeRequestOutbox(); err != nil { - return util.MakeError(err, "ActorInbox") - } - } else if err != nil { + if err := followActivity.MakeRequestOutbox(); err != nil { return util.MakeError(err, "ActorInbox") } } |