diff options
author | 2024-03-13 13:53:29 +0100 | |
---|---|---|
committer | 2024-03-13 13:53:29 +0100 | |
commit | ab2d063fcb04f241a3147c843a021491f5fc0a55 (patch) | |
tree | 3d2eff864e8b19d4d9a24f4f1fe92feda8ee4dac /internal/processing/workers/fromfediapi_move.go | |
parent | [bugfix]: Add missing Link headers in Swagger spec (#2751) (diff) | |
download | gotosocial-ab2d063fcb04f241a3147c843a021491f5fc0a55.tar.xz |
[feature] Process outgoing Move from clientAPI (#2750)
* prevent moved accounts from taking create-type actions
* update move logic
* federate move out
* indicate on web profile when an account has moved
* [docs] Add migration docs section
* lock while checking + setting move state
* use redirectFollowers func for clientAPI as well
* comment typo
* linter? i barely know 'er!
* Update internal/uris/uri.go
Co-authored-by: Daenney <daenney@users.noreply.github.com>
* add a couple tests for move
* fix little mistake exposed by tests (thanks tests)
* ensure Move marked as successful
* attach shared util funcs to struct
* lock whole account when doing move
* move moving check to after error check
* replace repeated text with error func
* linterrrrrr!!!!
* catch self follow case
---------
Co-authored-by: Daenney <daenney@users.noreply.github.com>
Diffstat (limited to 'internal/processing/workers/fromfediapi_move.go')
-rw-r--r-- | internal/processing/workers/fromfediapi_move.go | 95 |
1 files changed, 1 insertions, 94 deletions
diff --git a/internal/processing/workers/fromfediapi_move.go b/internal/processing/workers/fromfediapi_move.go index 2223a21f5..0188a5d14 100644 --- a/internal/processing/workers/fromfediapi_move.go +++ b/internal/processing/workers/fromfediapi_move.go @@ -22,7 +22,6 @@ import ( "errors" "time" - apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/federation/dereferencing" "github.com/superseriousbusiness/gotosocial/internal/gtscontext" @@ -380,7 +379,7 @@ func (p *fediAPI) MoveAccount(ctx context.Context, fMsg messages.FromFediAPI) er // Transfer originAcct's followers // on this instance to targetAcct. - redirectOK := p.RedirectAccountFollowers( + redirectOK := p.utilF.redirectFollowers( ctx, originAcct, targetAcct, @@ -422,98 +421,6 @@ func (p *fediAPI) MoveAccount(ctx context.Context, fMsg messages.FromFediAPI) er return nil } -// RedirectAccountFollowers redirects all local -// followers of originAcct to targetAcct. -// -// Both accounts must be fully dereferenced -// already, and the Move must be valid. -// -// Callers to this function MUST have obtained -// a lock already by calling FedLocks.Lock. -// -// Return bool will be true if all goes OK. -func (p *fediAPI) RedirectAccountFollowers( - ctx context.Context, - originAcct *gtsmodel.Account, - targetAcct *gtsmodel.Account, -) bool { - // Any local followers of originAcct should - // send follow requests to targetAcct instead, - // and have followers of originAcct removed. - // - // Select local followers with barebones, since - // we only need follow.Account and we can get - // that ourselves. - followers, err := p.state.DB.GetAccountLocalFollowers( - gtscontext.SetBarebones(ctx), - originAcct.ID, - ) - if err != nil && !errors.Is(err, db.ErrNoEntries) { - log.Errorf(ctx, - "db error getting follows targeting originAcct: %v", - err, - ) - return false - } - - for _, follow := range followers { - // Fetch the local account that - // owns the follow targeting originAcct. - if follow.Account, err = p.state.DB.GetAccountByID( - gtscontext.SetBarebones(ctx), - follow.AccountID, - ); err != nil { - log.Errorf(ctx, - "db error getting follow account %s: %v", - follow.AccountID, err, - ) - return false - } - - // Use the account processor FollowCreate - // function to send off the new follow, - // carrying over the Reblogs and Notify - // values from the old follow to the new. - // - // This will also handle cases where our - // account has already followed the target - // account, by just updating the existing - // follow of target account. - if _, err := p.account.FollowCreate( - ctx, - follow.Account, - &apimodel.AccountFollowRequest{ - ID: targetAcct.ID, - Reblogs: follow.ShowReblogs, - Notify: follow.Notify, - }, - ); err != nil { - log.Errorf(ctx, - "error creating new follow for account %s: %v", - follow.AccountID, err, - ) - return false - } - - // New follow is in the process of - // sending, remove the existing follow. - // This will send out an Undo Activity for each Follow. - if _, err := p.account.FollowRemove( - ctx, - follow.Account, - follow.TargetAccountID, - ); err != nil { - log.Errorf(ctx, - "error removing old follow for account %s: %v", - follow.AccountID, err, - ) - return false - } - } - - return true -} - // RemoveAccountFollowing removes all // follows owned by the move originAcct. // |