diff options
Diffstat (limited to 'internal/processing/synchronous')
-rw-r--r-- | internal/processing/synchronous/status/boost.go | 10 | ||||
-rw-r--r-- | internal/processing/synchronous/status/boostedby.go | 8 | ||||
-rw-r--r-- | internal/processing/synchronous/status/context.go | 59 | ||||
-rw-r--r-- | internal/processing/synchronous/status/create.go | 3 | ||||
-rw-r--r-- | internal/processing/synchronous/status/delete.go | 8 | ||||
-rw-r--r-- | internal/processing/synchronous/status/fave.go | 10 | ||||
-rw-r--r-- | internal/processing/synchronous/status/favedby.go | 8 | ||||
-rw-r--r-- | internal/processing/synchronous/status/get.go | 10 | ||||
-rw-r--r-- | internal/processing/synchronous/status/status.go | 3 | ||||
-rw-r--r-- | internal/processing/synchronous/status/unfave.go | 19 |
10 files changed, 73 insertions, 65 deletions
diff --git a/internal/processing/synchronous/status/boost.go b/internal/processing/synchronous/status/boost.go index a746e9fd8..93d0f19de 100644 --- a/internal/processing/synchronous/status/boost.go +++ b/internal/processing/synchronous/status/boost.go @@ -24,14 +24,8 @@ func (p *processor) Boost(account *gtsmodel.Account, application *gtsmodel.Appli return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching target account %s: %s", targetStatus.AccountID, err)) } - l.Trace("going to get relevant accounts") - relevantAccounts, err := p.db.PullRelevantAccountsFromStatus(targetStatus) - if err != nil { - return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching related accounts for status %s: %s", targetStatusID, err)) - } - l.Trace("going to see if status is visible") - visible, err := p.db.StatusVisible(targetStatus, account, relevantAccounts) + visible, err := p.filter.StatusVisible(targetStatus, account) if err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("error seeing if status %s is visible: %s", targetStatus.ID, err)) } @@ -70,7 +64,7 @@ func (p *processor) Boost(account *gtsmodel.Account, application *gtsmodel.Appli } // return the frontend representation of the new status to the submitter - mastoStatus, err := p.tc.StatusToMasto(boostWrapperStatus, account, account, targetAccount, nil, targetStatus) + mastoStatus, err := p.tc.StatusToMasto(boostWrapperStatus, account) if err != nil { return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status %s to frontend representation: %s", targetStatus.ID, err)) } diff --git a/internal/processing/synchronous/status/boostedby.go b/internal/processing/synchronous/status/boostedby.go index 8ebfcebc0..b352178e3 100644 --- a/internal/processing/synchronous/status/boostedby.go +++ b/internal/processing/synchronous/status/boostedby.go @@ -24,14 +24,8 @@ func (p *processor) BoostedBy(account *gtsmodel.Account, targetStatusID string) return nil, gtserror.NewErrorNotFound(fmt.Errorf("StatusBoostedBy: error fetching target account %s: %s", targetStatus.AccountID, err)) } - l.Trace("going to get relevant accounts") - relevantAccounts, err := p.db.PullRelevantAccountsFromStatus(targetStatus) - if err != nil { - return nil, gtserror.NewErrorNotFound(fmt.Errorf("StatusBoostedBy: error fetching related accounts for status %s: %s", targetStatusID, err)) - } - l.Trace("going to see if status is visible") - visible, err := p.db.StatusVisible(targetStatus, account, relevantAccounts) + visible, err := p.filter.StatusVisible(targetStatus, account) if err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("StatusBoostedBy: error seeing if status %s is visible: %s", targetStatus.ID, err)) } diff --git a/internal/processing/synchronous/status/context.go b/internal/processing/synchronous/status/context.go index cac86815e..72b9b5623 100644 --- a/internal/processing/synchronous/status/context.go +++ b/internal/processing/synchronous/status/context.go @@ -1,14 +1,69 @@ package status import ( + "fmt" + "sort" + apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" + "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtserror" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" ) func (p *processor) Context(account *gtsmodel.Account, targetStatusID string) (*apimodel.Context, gtserror.WithCode) { - return &apimodel.Context{ + + context := &apimodel.Context{ Ancestors: []apimodel.Status{}, Descendants: []apimodel.Status{}, - }, nil + } + + targetStatus := >smodel.Status{} + if err := p.db.GetByID(targetStatusID, targetStatus); err != nil { + if _, ok := err.(db.ErrNoEntries); ok { + return nil, gtserror.NewErrorNotFound(err) + } + return nil, gtserror.NewErrorInternalError(err) + } + + visible, err := p.filter.StatusVisible(targetStatus, account) + if err != nil { + return nil, gtserror.NewErrorNotFound(err) + } + if !visible { + return nil, gtserror.NewErrorForbidden(fmt.Errorf("account with id %s does not have permission to view status %s", account.ID, targetStatusID)) + } + + parents, err := p.db.StatusParents(targetStatus) + if err != nil { + return nil, gtserror.NewErrorInternalError(err) + } + + for _, status := range parents { + if v, err := p.filter.StatusVisible(status, account); err == nil && v { + mastoStatus, err := p.tc.StatusToMasto(status, account) + if err == nil { + context.Ancestors = append(context.Ancestors, *mastoStatus) + } + } + } + + sort.Slice(context.Ancestors, func(i int, j int) bool { + return context.Ancestors[i].ID < context.Ancestors[j].ID + }) + + children, err := p.db.StatusChildren(targetStatus) + if err != nil { + return nil, gtserror.NewErrorInternalError(err) + } + + for _, status := range children { + if v, err := p.filter.StatusVisible(status, account); err == nil && v { + mastoStatus, err := p.tc.StatusToMasto(status, account) + if err == nil { + context.Descendants = append(context.Descendants, *mastoStatus) + } + } + } + + return context, nil } diff --git a/internal/processing/synchronous/status/create.go b/internal/processing/synchronous/status/create.go index 07f670d1a..aa7468ae5 100644 --- a/internal/processing/synchronous/status/create.go +++ b/internal/processing/synchronous/status/create.go @@ -28,6 +28,7 @@ func (p *processor) Create(account *gtsmodel.Account, application *gtsmodel.Appl UpdatedAt: time.Now(), Local: true, AccountID: account.ID, + AccountURI: account.URI, ContentWarning: form.SpoilerText, ActivityStreamsType: gtsmodel.ActivityStreamsNote, Sensitive: form.Sensitive, @@ -96,7 +97,7 @@ func (p *processor) Create(account *gtsmodel.Account, application *gtsmodel.Appl } // return the frontend representation of the new status to the submitter - mastoStatus, err := p.tc.StatusToMasto(newStatus, account, account, nil, newStatus.GTSReplyToAccount, nil) + mastoStatus, err := p.tc.StatusToMasto(newStatus, account) if err != nil { return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status %s to frontend representation: %s", newStatus.ID, err)) } diff --git a/internal/processing/synchronous/status/delete.go b/internal/processing/synchronous/status/delete.go index 7e251080a..5da196a9f 100644 --- a/internal/processing/synchronous/status/delete.go +++ b/internal/processing/synchronous/status/delete.go @@ -26,12 +26,6 @@ func (p *processor) Delete(account *gtsmodel.Account, targetStatusID string) (*a return nil, gtserror.NewErrorForbidden(errors.New("status doesn't belong to requesting account")) } - l.Trace("going to get relevant accounts") - relevantAccounts, err := p.db.PullRelevantAccountsFromStatus(targetStatus) - if err != nil { - return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching related accounts for status %s: %s", targetStatusID, err)) - } - var boostOfStatus *gtsmodel.Status if targetStatus.BoostOfID != "" { boostOfStatus = >smodel.Status{} @@ -40,7 +34,7 @@ func (p *processor) Delete(account *gtsmodel.Account, targetStatusID string) (*a } } - mastoStatus, err := p.tc.StatusToMasto(targetStatus, account, account, relevantAccounts.BoostedAccount, relevantAccounts.ReplyToAccount, boostOfStatus) + mastoStatus, err := p.tc.StatusToMasto(targetStatus, account) if err != nil { return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status %s to frontend representation: %s", targetStatus.ID, err)) } diff --git a/internal/processing/synchronous/status/fave.go b/internal/processing/synchronous/status/fave.go index b4622abbc..23f0d2944 100644 --- a/internal/processing/synchronous/status/fave.go +++ b/internal/processing/synchronous/status/fave.go @@ -26,12 +26,6 @@ func (p *processor) Fave(account *gtsmodel.Account, targetStatusID string) (*api return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching target account %s: %s", targetStatus.AccountID, err)) } - l.Trace("going to get relevant accounts") - relevantAccounts, err := p.db.PullRelevantAccountsFromStatus(targetStatus) - if err != nil { - return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching related accounts for status %s: %s", targetStatusID, err)) - } - var boostOfStatus *gtsmodel.Status if targetStatus.BoostOfID != "" { boostOfStatus = >smodel.Status{} @@ -41,7 +35,7 @@ func (p *processor) Fave(account *gtsmodel.Account, targetStatusID string) (*api } l.Trace("going to see if status is visible") - visible, err := p.db.StatusVisible(targetStatus, account, relevantAccounts) // requestingAccount might well be nil here, but StatusVisible knows how to take care of that + visible, err := p.filter.StatusVisible(targetStatus, account) // requestingAccount might well be nil here, but StatusVisible knows how to take care of that if err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("error seeing if status %s is visible: %s", targetStatus.ID, err)) } @@ -98,7 +92,7 @@ func (p *processor) Fave(account *gtsmodel.Account, targetStatusID string) (*api } // return the mastodon representation of the target status - mastoStatus, err := p.tc.StatusToMasto(targetStatus, targetAccount, account, relevantAccounts.BoostedAccount, relevantAccounts.ReplyToAccount, boostOfStatus) + mastoStatus, err := p.tc.StatusToMasto(targetStatus, account) if err != nil { return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status %s to frontend representation: %s", targetStatus.ID, err)) } diff --git a/internal/processing/synchronous/status/favedby.go b/internal/processing/synchronous/status/favedby.go index bda47d581..5194cc258 100644 --- a/internal/processing/synchronous/status/favedby.go +++ b/internal/processing/synchronous/status/favedby.go @@ -24,14 +24,8 @@ func (p *processor) FavedBy(account *gtsmodel.Account, targetStatusID string) ([ return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching target account %s: %s", targetStatus.AccountID, err)) } - l.Trace("going to get relevant accounts") - relevantAccounts, err := p.db.PullRelevantAccountsFromStatus(targetStatus) - if err != nil { - return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching related accounts for status %s: %s", targetStatusID, err)) - } - l.Trace("going to see if status is visible") - visible, err := p.db.StatusVisible(targetStatus, account, relevantAccounts) // requestingAccount might well be nil here, but StatusVisible knows how to take care of that + visible, err := p.filter.StatusVisible(targetStatus, account) if err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("error seeing if status %s is visible: %s", targetStatus.ID, err)) } diff --git a/internal/processing/synchronous/status/get.go b/internal/processing/synchronous/status/get.go index 7dbbb4e7d..9a70185b0 100644 --- a/internal/processing/synchronous/status/get.go +++ b/internal/processing/synchronous/status/get.go @@ -24,14 +24,8 @@ func (p *processor) Get(account *gtsmodel.Account, targetStatusID string) (*apim return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching target account %s: %s", targetStatus.AccountID, err)) } - l.Trace("going to get relevant accounts") - relevantAccounts, err := p.db.PullRelevantAccountsFromStatus(targetStatus) - if err != nil { - return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching related accounts for status %s: %s", targetStatusID, err)) - } - l.Trace("going to see if status is visible") - visible, err := p.db.StatusVisible(targetStatus, account, relevantAccounts) // requestingAccount might well be nil here, but StatusVisible knows how to take care of that + visible, err := p.filter.StatusVisible(targetStatus, account) // requestingAccount might well be nil here, but StatusVisible knows how to take care of that if err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("error seeing if status %s is visible: %s", targetStatus.ID, err)) } @@ -48,7 +42,7 @@ func (p *processor) Get(account *gtsmodel.Account, targetStatusID string) (*apim } } - mastoStatus, err := p.tc.StatusToMasto(targetStatus, targetAccount, account, relevantAccounts.BoostedAccount, relevantAccounts.ReplyToAccount, boostOfStatus) + mastoStatus, err := p.tc.StatusToMasto(targetStatus, account) if err != nil { return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status %s to frontend representation: %s", targetStatus.ID, err)) } diff --git a/internal/processing/synchronous/status/status.go b/internal/processing/synchronous/status/status.go index 5dd26a2f0..cfc48ff30 100644 --- a/internal/processing/synchronous/status/status.go +++ b/internal/processing/synchronous/status/status.go @@ -8,6 +8,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/gtserror" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/typeutils" + "github.com/superseriousbusiness/gotosocial/internal/visibility" ) // Processor wraps a bunch of functions for processing statuses. @@ -36,6 +37,7 @@ type processor struct { tc typeutils.TypeConverter config *config.Config db db.DB + filter visibility.Filter fromClientAPI chan gtsmodel.FromClientAPI log *logrus.Logger } @@ -46,6 +48,7 @@ func New(db db.DB, tc typeutils.TypeConverter, config *config.Config, fromClient tc: tc, config: config, db: db, + filter: visibility.NewFilter(db, log), fromClientAPI: fromClientAPI, log: log, } diff --git a/internal/processing/synchronous/status/unfave.go b/internal/processing/synchronous/status/unfave.go index 54cbbf509..b51daacb9 100644 --- a/internal/processing/synchronous/status/unfave.go +++ b/internal/processing/synchronous/status/unfave.go @@ -24,14 +24,8 @@ func (p *processor) Unfave(account *gtsmodel.Account, targetStatusID string) (*a return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching target account %s: %s", targetStatus.AccountID, err)) } - l.Trace("going to get relevant accounts") - relevantAccounts, err := p.db.PullRelevantAccountsFromStatus(targetStatus) - if err != nil { - return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching related accounts for status %s: %s", targetStatusID, err)) - } - l.Trace("going to see if status is visible") - visible, err := p.db.StatusVisible(targetStatus, account, relevantAccounts) // requestingAccount might well be nil here, but StatusVisible knows how to take care of that + visible, err := p.filter.StatusVisible(targetStatus, account) if err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("error seeing if status %s is visible: %s", targetStatus.ID, err)) } @@ -74,16 +68,7 @@ func (p *processor) Unfave(account *gtsmodel.Account, targetStatusID string) (*a } } - // return the status (whatever its state) back to the caller - var boostOfStatus *gtsmodel.Status - if targetStatus.BoostOfID != "" { - boostOfStatus = >smodel.Status{} - if err := p.db.GetByID(targetStatus.BoostOfID, boostOfStatus); err != nil { - return nil, gtserror.NewErrorInternalError(fmt.Errorf("error fetching boosted status %s: %s", targetStatus.BoostOfID, err)) - } - } - - mastoStatus, err := p.tc.StatusToMasto(targetStatus, targetAccount, account, relevantAccounts.BoostedAccount, relevantAccounts.ReplyToAccount, boostOfStatus) + mastoStatus, err := p.tc.StatusToMasto(targetStatus, account) if err != nil { return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status %s to frontend representation: %s", targetStatus.ID, err)) } |