diff options
Diffstat (limited to 'internal/processing/account')
-rw-r--r-- | internal/processing/account/createblock.go | 2 | ||||
-rw-r--r-- | internal/processing/account/delete.go | 4 | ||||
-rw-r--r-- | internal/processing/account/removeblock.go | 21 |
3 files changed, 12 insertions, 15 deletions
diff --git a/internal/processing/account/createblock.go b/internal/processing/account/createblock.go index dfe1475cb..5e5d9df46 100644 --- a/internal/processing/account/createblock.go +++ b/internal/processing/account/createblock.go @@ -65,7 +65,7 @@ func (p *processor) BlockCreate(ctx context.Context, requestingAccount *gtsmodel block.URI = uris.GenerateURIForBlock(requestingAccount.Username, newBlockID) // whack it in the database - if err := p.db.Put(ctx, block); err != nil { + if err := p.db.PutBlock(ctx, block); err != nil { return nil, gtserror.NewErrorInternalError(fmt.Errorf("BlockCreate: error creating block in db: %s", err)) } diff --git a/internal/processing/account/delete.go b/internal/processing/account/delete.go index 275806ec3..ebcc0df5c 100644 --- a/internal/processing/account/delete.go +++ b/internal/processing/account/delete.go @@ -99,12 +99,12 @@ func (p *processor) Delete(ctx context.Context, account *gtsmodel.Account, origi // 2. Delete account's blocks l.Trace("deleting account blocks") // first delete any blocks that this account created - if err := p.db.DeleteWhere(ctx, []db.Where{{Key: "account_id", Value: account.ID}}, &[]*gtsmodel.Block{}); err != nil { + if err := p.db.DeleteBlocksByOriginAccountID(ctx, account.ID); err != nil { l.Errorf("error deleting blocks created by account: %s", err) } // now delete any blocks that target this account - if err := p.db.DeleteWhere(ctx, []db.Where{{Key: "target_account_id", Value: account.ID}}, &[]*gtsmodel.Block{}); err != nil { + if err := p.db.DeleteBlocksByTargetAccountID(ctx, account.ID); err != nil { l.Errorf("error deleting blocks targeting account: %s", err) } diff --git a/internal/processing/account/removeblock.go b/internal/processing/account/removeblock.go index f15350a12..7f34e0f4f 100644 --- a/internal/processing/account/removeblock.go +++ b/internal/processing/account/removeblock.go @@ -20,6 +20,7 @@ package account import ( "context" + "errors" "fmt" "github.com/superseriousbusiness/gotosocial/internal/ap" @@ -37,23 +38,17 @@ func (p *processor) BlockRemove(ctx context.Context, requestingAccount *gtsmodel return nil, gtserror.NewErrorNotFound(fmt.Errorf("BlockCreate: error getting account %s from the db: %s", targetAccountID, err)) } - // check if a block exists, and remove it if it does (storing the URI for later) - var blockChanged bool - block := >smodel.Block{} - if err := p.db.GetWhere(ctx, []db.Where{ - {Key: "account_id", Value: requestingAccount.ID}, - {Key: "target_account_id", Value: targetAccountID}, - }, block); err == nil { + // check if a block exists, and remove it if it does + block, err := p.db.GetBlock(ctx, requestingAccount.ID, targetAccountID) + if err == nil { + // we got a block, remove it block.Account = requestingAccount block.TargetAccount = targetAccount - if err := p.db.DeleteByID(ctx, block.ID, >smodel.Block{}); err != nil { + if err := p.db.DeleteBlockByID(ctx, block.ID); err != nil { return nil, gtserror.NewErrorInternalError(fmt.Errorf("BlockRemove: error removing block from db: %s", err)) } - blockChanged = true - } - // block status changed so send the UNDO activity to the channel for async processing - if blockChanged { + // send the UNDO activity to the client worker for async processing p.clientWorker.Queue(messages.FromClientAPI{ APObjectType: ap.ActivityBlock, APActivityType: ap.ActivityUndo, @@ -61,6 +56,8 @@ func (p *processor) BlockRemove(ctx context.Context, requestingAccount *gtsmodel OriginAccount: requestingAccount, TargetAccount: targetAccount, }) + } else if !errors.Is(err, db.ErrNoEntries) { + return nil, gtserror.NewErrorInternalError(fmt.Errorf("BlockRemove: error getting possible block from db: %s", err)) } // return whatever relationship results from all this |