diff options
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") } } |