summaryrefslogtreecommitdiff
path: root/internal/processing/status/fave.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-10-25 16:04:53 +0200
committerLibravatar GitHub <noreply@github.com>2023-10-25 15:04:53 +0100
commitc7b6cd7770cad9bfdc23decffa7c4068752dbbbd (patch)
tree0f039fd34fb0287860fce06ff1c30dedd1882136 /internal/processing/status/fave.go
parent[bugfix] allow store smaller PNG image than 261 bytes (#2263) (#2298) (diff)
downloadgotosocial-c7b6cd7770cad9bfdc23decffa7c4068752dbbbd.tar.xz
[feature] Status thread mute/unmute functionality (#2278)
* add db models + functions for keeping track of threads * give em the old linty testy * create, remove, check mutes * swagger * testerino * test mute/unmute via api * add info log about new index creation * thread + allow muting of any remote statuses that mention a local account * IsStatusThreadMutedBy -> IsThreadMutedByAccount * use common processing functions in status processor * set = NULL * favee! * get rekt darlings, darlings get rekt * testrig please, have mercy muy liege
Diffstat (limited to 'internal/processing/status/fave.go')
-rw-r--r--internal/processing/status/fave.go54
1 files changed, 27 insertions, 27 deletions
diff --git a/internal/processing/status/fave.go b/internal/processing/status/fave.go
index e2bf03594..a16fb6620 100644
--- a/internal/processing/status/fave.go
+++ b/internal/processing/status/fave.go
@@ -33,16 +33,36 @@ 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)
+ if errWithCode != nil {
+ return nil, nil, errWithCode
+ }
+
+ if !*targetStatus.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)
+ 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
+}
+
// FaveCreate adds a fave for the requestingAccount, targeting the given status (no-op if fave already exists).
func (p *Processor) FaveCreate(ctx context.Context, requestingAccount *gtsmodel.Account, targetStatusID string) (*apimodel.Status, gtserror.WithCode) {
- targetStatus, existingFave, errWithCode := p.getFaveTarget(ctx, requestingAccount, targetStatusID)
+ targetStatus, existingFave, errWithCode := p.getFaveableStatus(ctx, requestingAccount, targetStatusID)
if errWithCode != nil {
return nil, errWithCode
}
if existingFave != nil {
// Status is already faveed.
- return p.apiStatus(ctx, targetStatus, requestingAccount)
+ return p.c.GetAPIStatus(ctx, requestingAccount, targetStatus)
}
// Create and store a new fave
@@ -72,19 +92,19 @@ func (p *Processor) FaveCreate(ctx context.Context, requestingAccount *gtsmodel.
TargetAccount: targetStatus.Account,
})
- return p.apiStatus(ctx, targetStatus, requestingAccount)
+ return p.c.GetAPIStatus(ctx, requestingAccount, targetStatus)
}
// FaveRemove removes a fave for the requesting account, targeting the given status (no-op if fave doesn't exist).
func (p *Processor) FaveRemove(ctx context.Context, requestingAccount *gtsmodel.Account, targetStatusID string) (*apimodel.Status, gtserror.WithCode) {
- targetStatus, existingFave, errWithCode := p.getFaveTarget(ctx, requestingAccount, targetStatusID)
+ targetStatus, existingFave, errWithCode := p.getFaveableStatus(ctx, requestingAccount, targetStatusID)
if errWithCode != nil {
return nil, errWithCode
}
if existingFave == nil {
// Status isn't faveed.
- return p.apiStatus(ctx, targetStatus, requestingAccount)
+ return p.c.GetAPIStatus(ctx, requestingAccount, targetStatus)
}
// We have a fave to remove.
@@ -102,12 +122,12 @@ func (p *Processor) FaveRemove(ctx context.Context, requestingAccount *gtsmodel.
TargetAccount: targetStatus.Account,
})
- return p.apiStatus(ctx, targetStatus, requestingAccount)
+ return p.c.GetAPIStatus(ctx, requestingAccount, targetStatus)
}
// FavedBy returns a slice of accounts that have liked the given status, filtered according to privacy settings.
func (p *Processor) FavedBy(ctx context.Context, requestingAccount *gtsmodel.Account, targetStatusID string) ([]*apimodel.Account, gtserror.WithCode) {
- targetStatus, errWithCode := p.getVisibleStatus(ctx, requestingAccount, targetStatusID)
+ targetStatus, errWithCode := p.c.GetVisibleTargetStatus(ctx, requestingAccount, targetStatusID)
if errWithCode != nil {
return nil, errWithCode
}
@@ -145,23 +165,3 @@ func (p *Processor) FavedBy(ctx context.Context, requestingAccount *gtsmodel.Acc
return apiAccounts, nil
}
-
-func (p *Processor) getFaveTarget(ctx context.Context, requestingAccount *gtsmodel.Account, targetStatusID string) (*gtsmodel.Status, *gtsmodel.StatusFave, gtserror.WithCode) {
- targetStatus, errWithCode := p.getVisibleStatus(ctx, requestingAccount, targetStatusID)
- if errWithCode != nil {
- return nil, nil, errWithCode
- }
-
- if !*targetStatus.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)
- 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
-}