summaryrefslogtreecommitdiff
path: root/internal/processing/account/createblock.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2021-08-20 12:26:56 +0200
committerLibravatar GitHub <noreply@github.com>2021-08-20 12:26:56 +0200
commit4920229a3b6e1d7dde536bc9ff766542b05d935c (patch)
treea9423beccec5331c372f01eedf38949dfb171e9e /internal/processing/account/createblock.go
parentText/status parsing fixes (#141) (diff)
downloadgotosocial-4920229a3b6e1d7dde536bc9ff766542b05d935c.tar.xz
Database updates (#144)
* start moving some database stuff around * continue moving db stuff around * more fiddling * more updates * and some more * and yet more * i broke SOMETHING but what, it's a mystery * tidy up * vendor ttlcache * use ttlcache * fix up some tests * rename some stuff * little reminder * some more updates
Diffstat (limited to 'internal/processing/account/createblock.go')
-rw-r--r--internal/processing/account/createblock.go26
1 files changed, 11 insertions, 15 deletions
diff --git a/internal/processing/account/createblock.go b/internal/processing/account/createblock.go
index 79ce03805..f10a2efa3 100644
--- a/internal/processing/account/createblock.go
+++ b/internal/processing/account/createblock.go
@@ -31,24 +31,20 @@ import (
func (p *processor) BlockCreate(requestingAccount *gtsmodel.Account, targetAccountID string) (*apimodel.Relationship, gtserror.WithCode) {
// make sure the target account actually exists in our db
- targetAcct := &gtsmodel.Account{}
- if err := p.db.GetByID(targetAccountID, targetAcct); err != nil {
- if _, ok := err.(db.ErrNoEntries); ok {
- return nil, gtserror.NewErrorNotFound(fmt.Errorf("BlockCreate: account %s not found in the db: %s", targetAccountID, err))
- }
+ targetAccount, err := p.db.GetAccountByID(targetAccountID)
+ if err != nil {
+ return nil, gtserror.NewErrorNotFound(fmt.Errorf("BlockCreate: error getting account %s from the db: %s", targetAccountID, err))
}
// if requestingAccount already blocks target account, we don't need to do anything
- block := &gtsmodel.Block{}
- if err := p.db.GetWhere([]db.Where{
- {Key: "account_id", Value: requestingAccount.ID},
- {Key: "target_account_id", Value: targetAccountID},
- }, block); err == nil {
- // block already exists, just return relationship
+ if blocked, err := p.db.IsBlocked(requestingAccount.ID, targetAccountID, false); err != nil {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("BlockCreate: error checking existence of block: %s", err))
+ } else if blocked {
return p.RelationshipGet(requestingAccount, targetAccountID)
}
// make the block
+ block := &gtsmodel.Block{}
newBlockID, err := id.NewULID()
if err != nil {
return nil, gtserror.NewErrorInternalError(err)
@@ -57,7 +53,7 @@ func (p *processor) BlockCreate(requestingAccount *gtsmodel.Account, targetAccou
block.AccountID = requestingAccount.ID
block.Account = requestingAccount
block.TargetAccountID = targetAccountID
- block.TargetAccount = targetAcct
+ block.TargetAccount = targetAccount
block.URI = util.GenerateURIForBlock(requestingAccount.Username, p.config.Protocol, p.config.Host, newBlockID)
// whack it in the database
@@ -123,7 +119,7 @@ func (p *processor) BlockCreate(requestingAccount *gtsmodel.Account, targetAccou
URI: frURI,
},
OriginAccount: requestingAccount,
- TargetAccount: targetAcct,
+ TargetAccount: targetAccount,
}
}
@@ -138,7 +134,7 @@ func (p *processor) BlockCreate(requestingAccount *gtsmodel.Account, targetAccou
URI: fURI,
},
OriginAccount: requestingAccount,
- TargetAccount: targetAcct,
+ TargetAccount: targetAccount,
}
}
@@ -148,7 +144,7 @@ func (p *processor) BlockCreate(requestingAccount *gtsmodel.Account, targetAccou
APActivityType: gtsmodel.ActivityStreamsCreate,
GTSModel: block,
OriginAccount: requestingAccount,
- TargetAccount: targetAcct,
+ TargetAccount: targetAccount,
}
return p.RelationshipGet(requestingAccount, targetAccountID)