From 4920229a3b6e1d7dde536bc9ff766542b05d935c Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Fri, 20 Aug 2021 12:26:56 +0200 Subject: 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 --- internal/processing/account/createfollow.go | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'internal/processing/account/createfollow.go') diff --git a/internal/processing/account/createfollow.go b/internal/processing/account/createfollow.go index e89db9d47..8c856a50e 100644 --- a/internal/processing/account/createfollow.go +++ b/internal/processing/account/createfollow.go @@ -31,38 +31,33 @@ import ( func (p *processor) FollowCreate(requestingAccount *gtsmodel.Account, form *apimodel.AccountFollowRequest) (*apimodel.Relationship, gtserror.WithCode) { // if there's a block between the accounts we shouldn't create the request ofc - blocked, err := p.db.Blocked(requestingAccount.ID, form.ID) - if err != nil { + if blocked, err := p.db.IsBlocked(requestingAccount.ID, form.ID, true); err != nil { return nil, gtserror.NewErrorInternalError(err) - } - if blocked { - return nil, gtserror.NewErrorNotFound(fmt.Errorf("accountfollowcreate: block exists between accounts")) + } else if blocked { + return nil, gtserror.NewErrorNotFound(fmt.Errorf("block exists between accounts")) } // make sure the target account actually exists in our db - targetAcct := >smodel.Account{} - if err := p.db.GetByID(form.ID, targetAcct); err != nil { - if _, ok := err.(db.ErrNoEntries); ok { + targetAcct, err := p.db.GetAccountByID(form.ID) + if err != nil { + if err == db.ErrNoEntries { return nil, gtserror.NewErrorNotFound(fmt.Errorf("accountfollowcreate: account %s not found in the db: %s", form.ID, err)) } + return nil, gtserror.NewErrorInternalError(err) } // check if a follow exists already - follows, err := p.db.Follows(requestingAccount, targetAcct) - if err != nil { + if follows, err := p.db.IsFollowing(requestingAccount, targetAcct); err != nil { return nil, gtserror.NewErrorInternalError(fmt.Errorf("accountfollowcreate: error checking follow in db: %s", err)) - } - if follows { + } else if follows { // already follows so just return the relationship return p.RelationshipGet(requestingAccount, form.ID) } - // check if a follow exists already - followRequested, err := p.db.FollowRequested(requestingAccount, targetAcct) - if err != nil { + // check if a follow request exists already + if followRequested, err := p.db.IsFollowRequested(requestingAccount, targetAcct); err != nil { return nil, gtserror.NewErrorInternalError(fmt.Errorf("accountfollowcreate: error checking follow request in db: %s", err)) - } - if followRequested { + } else if followRequested { // already follow requested so just return the relationship return p.RelationshipGet(requestingAccount, form.ID) } -- cgit v1.2.3