diff options
author | 2024-04-17 14:49:20 +0200 | |
---|---|---|
committer | 2024-04-17 13:49:20 +0100 | |
commit | cef9924d9a463df22da273cbca19735ec9e15243 (patch) | |
tree | 75271d1b4cd1ed8a91ec1d1a6360338866224a7f /internal/processing/status/get.go | |
parent | [feature] Stub status history endpoint (#2847) (diff) | |
download | gotosocial-cef9924d9a463df22da273cbca19735ec9e15243.tar.xz |
[feature] Status source endpoint (#2848)
* [feature] statusSource endpoint
* finish up
Diffstat (limited to 'internal/processing/status/get.go')
-rw-r--r-- | internal/processing/status/get.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/internal/processing/status/get.go b/internal/processing/status/get.go index 8b0c21adf..57fd4005c 100644 --- a/internal/processing/status/get.go +++ b/internal/processing/status/get.go @@ -73,6 +73,44 @@ func (p *Processor) Get(ctx context.Context, requestingAccount *gtsmodel.Account return p.c.GetAPIStatus(ctx, requestingAccount, targetStatus) } +// SourceGet returns the *apimodel.StatusSource version of the targetStatusID. +// Status must belong to the requester, and must not be a boost. +func (p *Processor) SourceGet(ctx context.Context, requestingAccount *gtsmodel.Account, targetStatusID string) (*apimodel.StatusSource, gtserror.WithCode) { + targetStatus, errWithCode := p.c.GetVisibleTargetStatus(ctx, + requestingAccount, + targetStatusID, + nil, // default freshness + ) + if errWithCode != nil { + return nil, errWithCode + } + + // Redirect to wrapped status if boost. + targetStatus, errWithCode = p.c.UnwrapIfBoost( + ctx, + requestingAccount, + targetStatus, + ) + if errWithCode != nil { + return nil, errWithCode + } + + if targetStatus.AccountID != requestingAccount.ID { + err := gtserror.Newf( + "status %s does not belong to account %s", + targetStatusID, requestingAccount.ID, + ) + return nil, gtserror.NewErrorNotFound(err) + } + + statusSource, err := p.converter.StatusToAPIStatusSource(ctx, targetStatus) + if err != nil { + err = gtserror.Newf("error converting status: %w", err) + return nil, gtserror.NewErrorInternalError(err) + } + return statusSource, nil +} + // WebGet gets the given status for web use, taking account of privacy settings. func (p *Processor) WebGet(ctx context.Context, targetStatusID string) (*apimodel.Status, gtserror.WithCode) { targetStatus, errWithCode := p.c.GetVisibleTargetStatus(ctx, |