diff options
author | 2021-10-01 19:08:50 +0200 | |
---|---|---|
committer | 2021-10-01 19:08:50 +0200 | |
commit | 9ce4234b9fd1e201faf015df52bfc35db259dd46 (patch) | |
tree | 98c27c89aa018fafabf00e4e462f1af84208c760 /internal/processing/fromfederator.go | |
parent | rework mention replacement func (#258) (diff) | |
download | gotosocial-9ce4234b9fd1e201faf015df52bfc35db259dd46.tar.xz |
Follow request auto approval (#259)
* start messing about
* fiddle more
* Tests & fiddling
Diffstat (limited to 'internal/processing/fromfederator.go')
-rw-r--r-- | internal/processing/fromfederator.go | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/internal/processing/fromfederator.go b/internal/processing/fromfederator.go index ffaf625d3..1ef29264e 100644 --- a/internal/processing/fromfederator.go +++ b/internal/processing/fromfederator.go @@ -77,14 +77,45 @@ func (p *processor) ProcessFromFederator(ctx context.Context, federatorMsg messa } case ap.ActivityFollow: // CREATE A FOLLOW REQUEST - incomingFollowRequest, ok := federatorMsg.GTSModel.(*gtsmodel.FollowRequest) + followRequest, ok := federatorMsg.GTSModel.(*gtsmodel.FollowRequest) if !ok { return errors.New("incomingFollowRequest was not parseable as *gtsmodel.FollowRequest") } - if err := p.notifyFollowRequest(ctx, incomingFollowRequest, federatorMsg.ReceivingAccount); err != nil { + if followRequest.TargetAccount == nil { + a, err := p.db.GetAccountByID(ctx, followRequest.TargetAccountID) + if err != nil { + return err + } + followRequest.TargetAccount = a + } + targetAccount := followRequest.TargetAccount + + if targetAccount.Locked { + // if the account is locked just notify the follow request and nothing else + return p.notifyFollowRequest(ctx, followRequest) + } + + if followRequest.Account == nil { + a, err := p.db.GetAccountByID(ctx, followRequest.AccountID) + if err != nil { + return err + } + followRequest.Account = a + } + originAccount := followRequest.Account + + // if the target account isn't locked, we should already accept the follow and notify about the new follower instead + follow, err := p.db.AcceptFollowRequest(ctx, followRequest.AccountID, followRequest.TargetAccountID) + if err != nil { return err } + + if err := p.federateAcceptFollowRequest(ctx, follow, originAccount, targetAccount); err != nil { + return err + } + + return p.notifyFollow(ctx, follow, targetAccount) case ap.ActivityAnnounce: // CREATE AN ANNOUNCE incomingAnnounce, ok := federatorMsg.GTSModel.(*gtsmodel.Status) @@ -194,14 +225,7 @@ func (p *processor) ProcessFromFederator(ctx context.Context, federatorMsg messa switch federatorMsg.APObjectType { case ap.ActivityFollow: // ACCEPT A FOLLOW - follow, ok := federatorMsg.GTSModel.(*gtsmodel.Follow) - if !ok { - return errors.New("follow was not parseable as *gtsmodel.Follow") - } - - if err := p.notifyFollow(ctx, follow, federatorMsg.ReceivingAccount); err != nil { - return err - } + // nothing to do here } } |