summaryrefslogtreecommitdiff
path: root/internal/processing/status/pin.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-03-20 19:10:08 +0100
committerLibravatar GitHub <noreply@github.com>2023-03-20 18:10:08 +0000
commite8595f0c64f527af0913d1a426b697e67ff74ac9 (patch)
treea5d45b1ad8b96318944408a23fda91f008643900 /internal/processing/status/pin.go
parent[chore]: Bump github.com/miekg/dns from 1.1.51 to 1.1.52 (#1636) (diff)
downloadgotosocial-e8595f0c64f527af0913d1a426b697e67ff74ac9.tar.xz
[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!
Diffstat (limited to 'internal/processing/status/pin.go')
-rw-r--r--internal/processing/status/pin.go50
1 files changed, 12 insertions, 38 deletions
diff --git a/internal/processing/status/pin.go b/internal/processing/status/pin.go
index cea509c11..1e7dc40e8 100644
--- a/internal/processing/status/pin.go
+++ b/internal/processing/status/pin.go
@@ -38,40 +38,24 @@ const allowedPinnedCount = 10
// - Status belongs to requesting account.
// - Status is public, unlisted, or followers-only.
// - Status is not a boost.
-func (p *Processor) getPinnableStatus(ctx context.Context, targetStatusID string, requestingAccountID string) (*gtsmodel.Status, gtserror.WithCode) {
- targetStatus, err := p.state.DB.GetStatusByID(ctx, targetStatusID)
- if err != nil {
- err = fmt.Errorf("error fetching status %s: %w", targetStatusID, err)
- return nil, gtserror.NewErrorNotFound(err)
- }
-
- requestingAccount, err := p.state.DB.GetAccountByID(ctx, requestingAccountID)
- if err != nil {
- return nil, gtserror.NewErrorInternalError(err)
- }
-
- visible, err := p.filter.StatusVisible(ctx, targetStatus, requestingAccount)
- if err != nil {
- return nil, gtserror.NewErrorInternalError(err)
- }
-
- if !visible {
- err = fmt.Errorf("status %s not visible to account %s", targetStatusID, requestingAccountID)
- return nil, gtserror.NewErrorNotFound(err)
+func (p *Processor) getPinnableStatus(ctx context.Context, requestingAccount *gtsmodel.Account, targetStatusID string) (*gtsmodel.Status, gtserror.WithCode) {
+ targetStatus, errWithCode := p.getVisibleStatus(ctx, requestingAccount, targetStatusID)
+ if errWithCode != nil {
+ return nil, errWithCode
}
- if targetStatus.AccountID != requestingAccountID {
- err = fmt.Errorf("status %s does not belong to account %s", targetStatusID, requestingAccountID)
+ if targetStatus.AccountID != requestingAccount.ID {
+ err := fmt.Errorf("status %s does not belong to account %s", targetStatusID, requestingAccount.ID)
return nil, gtserror.NewErrorUnprocessableEntity(err, err.Error())
}
if targetStatus.Visibility == gtsmodel.VisibilityDirect {
- err = errors.New("cannot pin direct messages")
+ err := errors.New("cannot pin direct messages")
return nil, gtserror.NewErrorUnprocessableEntity(err, err.Error())
}
if targetStatus.BoostOfID != "" {
- err = errors.New("cannot pin boosts")
+ err := errors.New("cannot pin boosts")
return nil, gtserror.NewErrorUnprocessableEntity(err, err.Error())
}
@@ -89,7 +73,7 @@ func (p *Processor) getPinnableStatus(ctx context.Context, targetStatusID string
//
// If the conditions can't be met, then code 422 Unprocessable Entity will be returned.
func (p *Processor) PinCreate(ctx context.Context, requestingAccount *gtsmodel.Account, targetStatusID string) (*apimodel.Status, gtserror.WithCode) {
- targetStatus, errWithCode := p.getPinnableStatus(ctx, targetStatusID, requestingAccount.ID)
+ targetStatus, errWithCode := p.getPinnableStatus(ctx, requestingAccount, targetStatusID)
if errWithCode != nil {
return nil, errWithCode
}
@@ -114,12 +98,7 @@ func (p *Processor) PinCreate(ctx context.Context, requestingAccount *gtsmodel.A
return nil, gtserror.NewErrorInternalError(fmt.Errorf("db error pinning status: %w", err))
}
- apiStatus, err := p.tc.StatusToAPIStatus(ctx, targetStatus, requestingAccount)
- if err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status %s to frontend representation: %w", targetStatus.ID, err))
- }
-
- return apiStatus, nil
+ return p.apiStatus(ctx, targetStatus, requestingAccount)
}
// PinRemove unpins the target status from the top of requestingAccount's profile, if possible.
@@ -134,7 +113,7 @@ func (p *Processor) PinCreate(ctx context.Context, requestingAccount *gtsmodel.A
// Unlike with PinCreate, statuses that are already unpinned will not return 422, but just do
// nothing and return the api model representation of the status, to conform to the masto API.
func (p *Processor) PinRemove(ctx context.Context, requestingAccount *gtsmodel.Account, targetStatusID string) (*apimodel.Status, gtserror.WithCode) {
- targetStatus, errWithCode := p.getPinnableStatus(ctx, targetStatusID, requestingAccount.ID)
+ targetStatus, errWithCode := p.getPinnableStatus(ctx, requestingAccount, targetStatusID)
if errWithCode != nil {
return nil, errWithCode
}
@@ -146,10 +125,5 @@ func (p *Processor) PinRemove(ctx context.Context, requestingAccount *gtsmodel.A
}
}
- apiStatus, err := p.tc.StatusToAPIStatus(ctx, targetStatus, requestingAccount)
- if err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status %s to frontend representation: %w", targetStatus.ID, err))
- }
-
- return apiStatus, nil
+ return p.apiStatus(ctx, targetStatus, requestingAccount)
}