summaryrefslogtreecommitdiff
path: root/internal/processing/status/pin.go
diff options
context:
space:
mode:
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)
}