summaryrefslogtreecommitdiff
path: root/internal/processing/workers
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/workers
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/workers')
-rw-r--r--internal/processing/workers/fromclientapi_test.go5
-rw-r--r--internal/processing/workers/surfacenotify.go7
-rw-r--r--internal/processing/workers/surfacetimeline.go34
3 files changed, 42 insertions, 4 deletions
diff --git a/internal/processing/workers/fromclientapi_test.go b/internal/processing/workers/fromclientapi_test.go
index c7c6e5c27..6a12ce043 100644
--- a/internal/processing/workers/fromclientapi_test.go
+++ b/internal/processing/workers/fromclientapi_test.go
@@ -28,6 +28,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
+ statusfilter "github.com/superseriousbusiness/gotosocial/internal/filter/status"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/id"
"github.com/superseriousbusiness/gotosocial/internal/messages"
@@ -154,6 +155,8 @@ func (suite *FromClientAPITestSuite) statusJSON(
ctx,
status,
requestingAccount,
+ statusfilter.FilterContextNone,
+ nil,
)
if err != nil {
suite.FailNow(err.Error())
@@ -258,7 +261,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusWithNotification() {
suite.FailNow("timed out waiting for new status notification")
}
- apiNotif, err := testStructs.TypeConverter.NotificationToAPINotification(ctx, notif)
+ apiNotif, err := testStructs.TypeConverter.NotificationToAPINotification(ctx, notif, nil)
if err != nil {
suite.FailNow(err.Error())
}
diff --git a/internal/processing/workers/surfacenotify.go b/internal/processing/workers/surfacenotify.go
index be729fa7e..a31946cc8 100644
--- a/internal/processing/workers/surfacenotify.go
+++ b/internal/processing/workers/surfacenotify.go
@@ -467,7 +467,12 @@ func (s *Surface) Notify(
unlock()
// Stream notification to the user.
- apiNotif, err := s.Converter.NotificationToAPINotification(ctx, notif)
+ filters, err := s.State.DB.GetFiltersForAccountID(ctx, targetAccount.ID)
+ if err != nil {
+ return gtserror.Newf("couldn't retrieve filters for account %s: %w", targetAccount.ID, err)
+ }
+
+ apiNotif, err := s.Converter.NotificationToAPINotification(ctx, notif, filters)
if err != nil {
return gtserror.Newf("error converting notification to api representation: %w", err)
}
diff --git a/internal/processing/workers/surfacetimeline.go b/internal/processing/workers/surfacetimeline.go
index 65b039939..32fdd66e2 100644
--- a/internal/processing/workers/surfacetimeline.go
+++ b/internal/processing/workers/surfacetimeline.go
@@ -22,6 +22,7 @@ import (
"errors"
"github.com/superseriousbusiness/gotosocial/internal/db"
+ statusfilter "github.com/superseriousbusiness/gotosocial/internal/filter/status"
"github.com/superseriousbusiness/gotosocial/internal/gtscontext"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
@@ -111,6 +112,11 @@ func (s *Surface) timelineAndNotifyStatusForFollowers(
continue
}
+ filters, err := s.State.DB.GetFiltersForAccountID(ctx, follow.AccountID)
+ if err != nil {
+ return gtserror.Newf("couldn't retrieve filters for account %s: %w", follow.AccountID, err)
+ }
+
// Add status to any relevant lists
// for this follow, if applicable.
s.listTimelineStatusForFollow(
@@ -118,6 +124,7 @@ func (s *Surface) timelineAndNotifyStatusForFollowers(
status,
follow,
&errs,
+ filters,
)
// Add status to home timeline for owner
@@ -129,6 +136,7 @@ func (s *Surface) timelineAndNotifyStatusForFollowers(
follow.Account,
status,
stream.TimelineHome,
+ filters,
)
if err != nil {
errs.Appendf("error home timelining status: %w", err)
@@ -180,6 +188,7 @@ func (s *Surface) listTimelineStatusForFollow(
status *gtsmodel.Status,
follow *gtsmodel.Follow,
errs *gtserror.MultiError,
+ filters []*gtsmodel.Filter,
) {
// To put this status in appropriate list timelines,
// we need to get each listEntry that pertains to
@@ -222,6 +231,7 @@ func (s *Surface) listTimelineStatusForFollow(
follow.Account,
status,
stream.TimelineList+":"+listEntry.ListID, // key streamType to this specific list
+ filters,
); err != nil {
errs.Appendf("error adding status to timeline for list %s: %w", listEntry.ListID, err)
// implicit continue
@@ -332,6 +342,7 @@ func (s *Surface) timelineStatus(
account *gtsmodel.Account,
status *gtsmodel.Status,
streamType string,
+ filters []*gtsmodel.Filter,
) (bool, error) {
// Ingest status into given timeline using provided function.
if inserted, err := ingest(ctx, timelineID, status); err != nil {
@@ -343,7 +354,12 @@ func (s *Surface) timelineStatus(
}
// The status was inserted so stream it to the user.
- apiStatus, err := s.Converter.StatusToAPIStatus(ctx, status, account)
+ apiStatus, err := s.Converter.StatusToAPIStatus(ctx,
+ status,
+ account,
+ statusfilter.FilterContextHome,
+ filters,
+ )
if err != nil {
err = gtserror.Newf("error converting status %s to frontend representation: %w", status.ID, err)
return true, err
@@ -457,6 +473,11 @@ func (s *Surface) timelineStatusUpdateForFollowers(
continue
}
+ filters, err := s.State.DB.GetFiltersForAccountID(ctx, follow.AccountID)
+ if err != nil {
+ return gtserror.Newf("couldn't retrieve filters for account %s: %w", follow.AccountID, err)
+ }
+
// Add status to any relevant lists
// for this follow, if applicable.
s.listTimelineStatusUpdateForFollow(
@@ -464,6 +485,7 @@ func (s *Surface) timelineStatusUpdateForFollowers(
status,
follow,
&errs,
+ filters,
)
// Add status to home timeline for owner
@@ -473,6 +495,7 @@ func (s *Surface) timelineStatusUpdateForFollowers(
follow.Account,
status,
stream.TimelineHome,
+ filters,
)
if err != nil {
errs.Appendf("error home timelining status: %w", err)
@@ -490,6 +513,7 @@ func (s *Surface) listTimelineStatusUpdateForFollow(
status *gtsmodel.Status,
follow *gtsmodel.Follow,
errs *gtserror.MultiError,
+ filters []*gtsmodel.Filter,
) {
// To put this status in appropriate list timelines,
// we need to get each listEntry that pertains to
@@ -530,6 +554,7 @@ func (s *Surface) listTimelineStatusUpdateForFollow(
follow.Account,
status,
stream.TimelineList+":"+listEntry.ListID, // key streamType to this specific list
+ filters,
); err != nil {
errs.Appendf("error adding status to timeline for list %s: %w", listEntry.ListID, err)
// implicit continue
@@ -544,8 +569,13 @@ func (s *Surface) timelineStreamStatusUpdate(
account *gtsmodel.Account,
status *gtsmodel.Status,
streamType string,
+ filters []*gtsmodel.Filter,
) error {
- apiStatus, err := s.Converter.StatusToAPIStatus(ctx, status, account)
+ apiStatus, err := s.Converter.StatusToAPIStatus(ctx, status, account, statusfilter.FilterContextHome, filters)
+ if errors.Is(err, statusfilter.ErrHideStatus) {
+ // Don't put this status in the stream.
+ return nil
+ }
if err != nil {
err = gtserror.Newf("error converting status %s to frontend representation: %w", status.ID, err)
return err