From e8595f0c64f527af0913d1a426b697e67ff74ac9 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Mon, 20 Mar 2023 19:10:08 +0100 Subject: [chore] Refactor account deleting/block logic, tidy up some other processing things (#1599) * start refactoring account deletion * update to use state.DB * further messing about * some more tidying up * more tidying, cleaning, nice-making * further adventures in refactoring and the woes of technical debt * update fr accept/reject * poking + prodding * fix up deleting * create fave uri * don't log using requestingAccount.ID because it might be nil * move getBookmarks function * use exists query to check for status bookmark * use deletenotifications func * fiddle * delete follow request notif * split up some db functions * Fix possible nil pointer panic * fix more possible nil pointers * fix license headers * warn when follow missing (target) account * return wrapped err when bookmark/fave models can't be retrieved * simplify self account delete * warn log likely race condition * de-sillify status delete loop * move error check due north * warn when unfollowSideEffects has no target account * warn when no boost account is found * warn + dump follow when no account * more warnings * warn on fave account not set * move for loop inside anonymous function * fix funky logic * don't remove mutual account items on block; do make sure unfollow occurs in both directions! --- internal/processing/fromclientapi.go | 64 ++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 36 deletions(-) (limited to 'internal/processing/fromclientapi.go') diff --git a/internal/processing/fromclientapi.go b/internal/processing/fromclientapi.go index a4d4521ce..490fc7d34 100644 --- a/internal/processing/fromclientapi.go +++ b/internal/processing/fromclientapi.go @@ -139,8 +139,8 @@ func (p *Processor) processCreateAccountFromClientAPI(ctx context.Context, clien return errors.New("account was not parseable as *gtsmodel.Account") } - // return if the account isn't from this domain - if account.Domain != "" { + // Do nothing if this isn't our activity. + if !account.IsLocal() { return nil } @@ -383,8 +383,8 @@ func (p *Processor) processReportAccountFromClientAPI(ctx context.Context, clien // TODO: move all the below functions into federation.Federator func (p *Processor) federateAccountDelete(ctx context.Context, account *gtsmodel.Account) error { - // do nothing if this isn't our account - if account.Domain != "" { + // Do nothing if this isn't our activity. + if !account.IsLocal() { return nil } @@ -449,8 +449,8 @@ func (p *Processor) federateStatus(ctx context.Context, status *gtsmodel.Status) status.Account = statusAccount } - // do nothing if this isn't our status - if status.Account.Domain != "" { + // Do nothing if this isn't our activity. + if !status.Account.IsLocal() { return nil } @@ -482,8 +482,8 @@ func (p *Processor) federateStatusDelete(ctx context.Context, status *gtsmodel.S status.Account = statusAccount } - // do nothing if this isn't our status - if status.Account.Domain != "" { + // Do nothing if this isn't our activity. + if !status.Account.IsLocal() { return nil } @@ -502,8 +502,8 @@ func (p *Processor) federateStatusDelete(ctx context.Context, status *gtsmodel.S } func (p *Processor) federateFollow(ctx context.Context, followRequest *gtsmodel.FollowRequest, originAccount *gtsmodel.Account, targetAccount *gtsmodel.Account) error { - // if both accounts are local there's nothing to do here - if originAccount.Domain == "" && targetAccount.Domain == "" { + // Do nothing if both accounts are local. + if originAccount.IsLocal() && targetAccount.IsLocal() { return nil } @@ -524,8 +524,8 @@ func (p *Processor) federateFollow(ctx context.Context, followRequest *gtsmodel. } func (p *Processor) federateUnfollow(ctx context.Context, follow *gtsmodel.Follow, originAccount *gtsmodel.Account, targetAccount *gtsmodel.Account) error { - // if both accounts are local there's nothing to do here - if originAccount.Domain == "" && targetAccount.Domain == "" { + // Do nothing if both accounts are local. + if originAccount.IsLocal() && targetAccount.IsLocal() { return nil } @@ -565,8 +565,8 @@ func (p *Processor) federateUnfollow(ctx context.Context, follow *gtsmodel.Follo } func (p *Processor) federateUnfave(ctx context.Context, fave *gtsmodel.StatusFave, originAccount *gtsmodel.Account, targetAccount *gtsmodel.Account) error { - // if both accounts are local there's nothing to do here - if originAccount.Domain == "" && targetAccount.Domain == "" { + // Do nothing if both accounts are local. + if originAccount.IsLocal() && targetAccount.IsLocal() { return nil } @@ -604,8 +604,8 @@ func (p *Processor) federateUnfave(ctx context.Context, fave *gtsmodel.StatusFav } func (p *Processor) federateUnannounce(ctx context.Context, boost *gtsmodel.Status, originAccount *gtsmodel.Account, targetAccount *gtsmodel.Account) error { - if originAccount.Domain != "" { - // nothing to do here + // Do nothing if this isn't our activity. + if !originAccount.IsLocal() { return nil } @@ -657,13 +657,9 @@ func (p *Processor) federateAcceptFollowRequest(ctx context.Context, follow *gts } targetAccount := follow.TargetAccount - // if target account isn't from our domain we shouldn't do anything - if targetAccount.Domain != "" { - return nil - } - - // if both accounts are local there's nothing to do here - if originAccount.Domain == "" && targetAccount.Domain == "" { + // Do nothing if target account *isn't* local, + // or both origin + target *are* local. + if targetAccount.IsRemote() || originAccount.IsLocal() { return nil } @@ -730,13 +726,9 @@ func (p *Processor) federateRejectFollowRequest(ctx context.Context, followReque } targetAccount := followRequest.TargetAccount - // if target account isn't from our domain we shouldn't do anything - if targetAccount.Domain != "" { - return nil - } - - // if both accounts are local there's nothing to do here - if originAccount.Domain == "" && targetAccount.Domain == "" { + // Do nothing if target account *isn't* local, + // or both origin + target *are* local. + if targetAccount.IsRemote() || originAccount.IsLocal() { return nil } @@ -786,8 +778,8 @@ func (p *Processor) federateRejectFollowRequest(ctx context.Context, followReque } func (p *Processor) federateFave(ctx context.Context, fave *gtsmodel.StatusFave, originAccount *gtsmodel.Account, targetAccount *gtsmodel.Account) error { - // if both accounts are local there's nothing to do here - if originAccount.Domain == "" && targetAccount.Domain == "" { + // Do nothing if both accounts are local. + if originAccount.IsLocal() && targetAccount.IsLocal() { return nil } @@ -857,8 +849,8 @@ func (p *Processor) federateBlock(ctx context.Context, block *gtsmodel.Block) er block.TargetAccount = blockTargetAccount } - // if both accounts are local there's nothing to do here - if block.Account.Domain == "" && block.TargetAccount.Domain == "" { + // Do nothing if both accounts are local. + if block.Account.IsLocal() && block.TargetAccount.IsLocal() { return nil } @@ -893,8 +885,8 @@ func (p *Processor) federateUnblock(ctx context.Context, block *gtsmodel.Block) block.TargetAccount = blockTargetAccount } - // if both accounts are local there's nothing to do here - if block.Account.Domain == "" && block.TargetAccount.Domain == "" { + // Do nothing if both accounts are local. + if block.Account.IsLocal() && block.TargetAccount.IsLocal() { return nil } -- cgit v1.2.3