[bugfix/chore] Announce reliability updates (#2405)

* [bugfix/chore] `Announce` updates

* test update

* fix tests

* TestParseAnnounce

* update comments

* don't lock/unlock, change function signature

* naming stuff

* don't check domain block twice

* UnwrapIfBoost

* beep boop
This commit is contained in:
tobi 2023-12-01 15:27:15 +01:00 committed by GitHub
commit 0e2c342191
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 425 additions and 285 deletions

View file

@ -33,24 +33,46 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/uris"
)
func (p *Processor) getFaveableStatus(ctx context.Context, requestingAccount *gtsmodel.Account, targetStatusID string) (*gtsmodel.Status, *gtsmodel.StatusFave, gtserror.WithCode) {
targetStatus, errWithCode := p.c.GetVisibleTargetStatus(ctx, requestingAccount, targetStatusID)
func (p *Processor) getFaveableStatus(
ctx context.Context,
requester *gtsmodel.Account,
targetID string,
) (
*gtsmodel.Status,
*gtsmodel.StatusFave,
gtserror.WithCode,
) {
// Get target status and ensure it's not a boost.
target, errWithCode := p.c.GetVisibleTargetStatus(
ctx,
requester,
targetID,
)
if errWithCode != nil {
return nil, nil, errWithCode
}
if !*targetStatus.Likeable {
target, errWithCode = p.c.UnwrapIfBoost(
ctx,
requester,
target,
)
if errWithCode != nil {
return nil, nil, errWithCode
}
if !*target.Likeable {
err := errors.New("status is not faveable")
return nil, nil, gtserror.NewErrorForbidden(err, err.Error())
}
fave, err := p.state.DB.GetStatusFave(ctx, requestingAccount.ID, targetStatusID)
fave, err := p.state.DB.GetStatusFave(ctx, requester.ID, target.ID)
if err != nil && !errors.Is(err, db.ErrNoEntries) {
err = fmt.Errorf("getFaveTarget: error checking existing fave: %w", err)
return nil, nil, gtserror.NewErrorInternalError(err)
}
return targetStatus, fave, nil
return target, fave, nil
}
// FaveCreate adds a fave for the requestingAccount, targeting the given status (no-op if fave already exists).