summaryrefslogtreecommitdiff
path: root/internal/processing/common
diff options
context:
space:
mode:
authorLibravatar Vyr Cossont <VyrCossont@users.noreply.github.com>2024-05-06 04:49:08 -0700
committerLibravatar GitHub <noreply@github.com>2024-05-06 12:49:08 +0100
commit45f4afe60e29e147e3adfaa4d7b66ca58e22b1de (patch)
tree85b14b05516274f504c7237540f8c8fb3b9ae68e /internal/processing/common
parent[chore]: Bump golang.org/x/oauth2 from 0.19.0 to 0.20.0 (#2900) (diff)
downloadgotosocial-45f4afe60e29e147e3adfaa4d7b66ca58e22b1de.tar.xz
feature: filters v2 server-side warning/hiding (#2793)
* Remove dead code * Filter statuses when converting to frontend representation * status.filtered is an array * Make matching case-insensitive * Remove TODOs that don't need to be done now * Add missing filter check for notification * lint: rename ErrHideStatus * APIFilterActionToFilterAction not used yet * swaggerino docseroni * Address review comments * Add apimodel.FilterActionNone --------- Co-authored-by: tobi <31960611+tsmethurst@users.noreply.github.com> Co-authored-by: tobi <tobi.smethurst@protonmail.com>
Diffstat (limited to 'internal/processing/common')
-rw-r--r--internal/processing/common/status.go84
1 files changed, 2 insertions, 82 deletions
diff --git a/internal/processing/common/status.go b/internal/processing/common/status.go
index 308f5173f..bb46ee38c 100644
--- a/internal/processing/common/status.go
+++ b/internal/processing/common/status.go
@@ -24,6 +24,7 @@ import (
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/federation/dereferencing"
+ statusfilter "github.com/superseriousbusiness/gotosocial/internal/filter/status"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/log"
@@ -184,7 +185,7 @@ func (p *Processor) GetAPIStatus(
apiStatus *apimodel.Status,
errWithCode gtserror.WithCode,
) {
- apiStatus, err := p.converter.StatusToAPIStatus(ctx, target, requester)
+ apiStatus, err := p.converter.StatusToAPIStatus(ctx, target, requester, statusfilter.FilterContextNone, nil)
if err != nil {
err = gtserror.Newf("error converting status: %w", err)
return nil, gtserror.NewErrorInternalError(err)
@@ -192,87 +193,6 @@ func (p *Processor) GetAPIStatus(
return apiStatus, nil
}
-// GetVisibleAPIStatuses converts an array of gtsmodel.Status (inputted by next function) into
-// API model statuses, checking first for visibility. Please note that all errors will be
-// logged at ERROR level, but will not be returned. Callers are likely to run into show-stopping
-// errors in the lead-up to this function, whereas calling this should not be a show-stopper.
-func (p *Processor) GetVisibleAPIStatuses(
- ctx context.Context,
- requester *gtsmodel.Account,
- next func(int) *gtsmodel.Status,
- length int,
-) []*apimodel.Status {
- return p.getVisibleAPIStatuses(ctx, 3, requester, next, length)
-}
-
-// GetVisibleAPIStatusesPaged is functionally equivalent to GetVisibleAPIStatuses(),
-// except the statuses are returned as a converted slice of statuses as interface{}.
-func (p *Processor) GetVisibleAPIStatusesPaged(
- ctx context.Context,
- requester *gtsmodel.Account,
- next func(int) *gtsmodel.Status,
- length int,
-) []interface{} {
- statuses := p.getVisibleAPIStatuses(ctx, 3, requester, next, length)
- if len(statuses) == 0 {
- return nil
- }
- items := make([]interface{}, len(statuses))
- for i, status := range statuses {
- items[i] = status
- }
- return items
-}
-
-func (p *Processor) getVisibleAPIStatuses(
- ctx context.Context,
- calldepth int, // used to skip wrapping func above these's names
- requester *gtsmodel.Account,
- next func(int) *gtsmodel.Status,
- length int,
-) []*apimodel.Status {
- // Start new log entry with
- // the above calling func's name.
- l := log.
- WithContext(ctx).
- WithField("caller", log.Caller(calldepth+1))
-
- // Preallocate slice according to expected length.
- statuses := make([]*apimodel.Status, 0, length)
-
- for i := 0; i < length; i++ {
- // Get next status.
- status := next(i)
- if status == nil {
- continue
- }
-
- // Check whether this status is visible to requesting account.
- visible, err := p.filter.StatusVisible(ctx, requester, status)
- if err != nil {
- l.Errorf("error checking status visibility: %v", err)
- continue
- }
-
- if !visible {
- // Not visible to requester.
- continue
- }
-
- // Convert the status to an API model representation.
- apiStatus, err := p.converter.StatusToAPIStatus(ctx, status, requester)
- if err != nil {
- l.Errorf("error converting status: %v", err)
- continue
- }
-
- // Append API model to return slice.
- statuses = append(statuses, apiStatus)
- }
-
- return statuses
-}
-
// InvalidateTimelinedStatus is a shortcut function for invalidating the cached
// representation one status in the home timeline and all list timelines of the
// given accountID. It should only be called in cases where a status update