[bugfix] Ensure side effects handled for local unlocked follows (#2998)
This commit is contained in:
parent
978b4176f1
commit
20877c1474
|
@ -30,6 +30,7 @@ import (
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/id"
|
"github.com/superseriousbusiness/gotosocial/internal/id"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/messages"
|
"github.com/superseriousbusiness/gotosocial/internal/messages"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/uris"
|
"github.com/superseriousbusiness/gotosocial/internal/uris"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FollowCreate handles a follow request to an account, either remote or local.
|
// FollowCreate handles a follow request to an account, either remote or local.
|
||||||
|
@ -98,25 +99,29 @@ func (p *Processor) FollowCreate(ctx context.Context, requestingAccount *gtsmode
|
||||||
Notify: form.Notify,
|
Notify: form.Notify,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Insert the new follow request.
|
||||||
if err := p.state.DB.PutFollowRequest(ctx, fr); err != nil {
|
if err := p.state.DB.PutFollowRequest(ctx, fr); err != nil {
|
||||||
err = gtserror.Newf("error creating follow request in db: %s", err)
|
err = gtserror.Newf("error creating follow request in db: %s", err)
|
||||||
return nil, gtserror.NewErrorInternalError(err)
|
return nil, gtserror.NewErrorInternalError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if targetAccount.IsLocal() && !*targetAccount.Locked {
|
// And get the new relationship state.
|
||||||
// If the target account is local and not locked,
|
rel, errWithCode := p.RelationshipGet(ctx, requestingAccount, form.ID)
|
||||||
// we can already accept the follow request and
|
if errWithCode != nil {
|
||||||
// skip any further processing.
|
return nil, errWithCode
|
||||||
//
|
|
||||||
// Because we know the requestingAccount is also
|
|
||||||
// local, we don't need to federate the accept out.
|
|
||||||
if _, err := p.state.DB.AcceptFollowRequest(ctx, requestingAccount.ID, form.ID); err != nil {
|
|
||||||
err = gtserror.Newf("error accepting follow request for local unlocked account: %w", err)
|
|
||||||
return nil, gtserror.NewErrorInternalError(err)
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// Otherwise we leave the follow request as it is,
|
// For unlocked accounts on the same instance,
|
||||||
// and we handle the rest of the process async.
|
// we can already optimistically show the follow
|
||||||
|
// request as accepted in the returned relationship.
|
||||||
|
if targetAccount.IsLocal() && !*targetAccount.Locked {
|
||||||
|
rel.Requested = false
|
||||||
|
rel.Following = true
|
||||||
|
rel.ShowingReblogs = util.PtrValueOr(fr.ShowReblogs, true)
|
||||||
|
rel.Notifying = util.PtrValueOr(fr.Notify, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle side effects async.
|
||||||
p.state.Workers.Client.Queue.Push(&messages.FromClientAPI{
|
p.state.Workers.Client.Queue.Push(&messages.FromClientAPI{
|
||||||
APObjectType: ap.ActivityFollow,
|
APObjectType: ap.ActivityFollow,
|
||||||
APActivityType: ap.ActivityCreate,
|
APActivityType: ap.ActivityCreate,
|
||||||
|
@ -124,9 +129,8 @@ func (p *Processor) FollowCreate(ctx context.Context, requestingAccount *gtsmode
|
||||||
Origin: requestingAccount,
|
Origin: requestingAccount,
|
||||||
Target: targetAccount,
|
Target: targetAccount,
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
return p.RelationshipGet(ctx, requestingAccount, form.ID)
|
return rel, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// FollowRemove handles the removal of a follow/follow request to an account, either remote or local.
|
// FollowRemove handles the removal of a follow/follow request to an account, either remote or local.
|
||||||
|
|
|
@ -305,6 +305,30 @@ func (p *clientAPI) CreateFollowReq(ctx context.Context, cMsg *messages.FromClie
|
||||||
return gtserror.Newf("%T not parseable as *gtsmodel.FollowRequest", cMsg.GTSModel)
|
return gtserror.Newf("%T not parseable as *gtsmodel.FollowRequest", cMsg.GTSModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If target is a local, unlocked account,
|
||||||
|
// we can skip side effects for the follow
|
||||||
|
// request and accept the follow immediately.
|
||||||
|
if cMsg.Target.IsLocal() && !*cMsg.Target.Locked {
|
||||||
|
// Accept the FR first to get the Follow.
|
||||||
|
follow, err := p.state.DB.AcceptFollowRequest(
|
||||||
|
ctx,
|
||||||
|
cMsg.Origin.ID,
|
||||||
|
cMsg.Target.ID,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return gtserror.Newf("db error accepting follow req: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use AcceptFollow to do side effects.
|
||||||
|
return p.AcceptFollow(ctx, &messages.FromClientAPI{
|
||||||
|
APObjectType: ap.ActivityFollow,
|
||||||
|
APActivityType: ap.ActivityAccept,
|
||||||
|
GTSModel: follow,
|
||||||
|
Origin: cMsg.Origin,
|
||||||
|
Target: cMsg.Target,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Update stats for the target account.
|
// Update stats for the target account.
|
||||||
if err := p.utils.incrementFollowRequestsCount(ctx, cMsg.Target); err != nil {
|
if err := p.utils.incrementFollowRequestsCount(ctx, cMsg.Target); err != nil {
|
||||||
log.Errorf(ctx, "error updating account stats: %v", err)
|
log.Errorf(ctx, "error updating account stats: %v", err)
|
||||||
|
|
Loading…
Reference in New Issue