summaryrefslogtreecommitdiff
path: root/internal/processing/workers
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-07-24 13:27:42 +0200
committerLibravatar GitHub <noreply@github.com>2024-07-24 12:27:42 +0100
commitc9b6220fef01dce80a31436660cd06b4e1db030f (patch)
tree5fbade865a920a5ea04fdd63763eca1880d60c5d /internal/processing/workers
parent[chore] renames the `GTS` caches to `DB` caches (#3127) (diff)
downloadgotosocial-c9b6220fef01dce80a31436660cd06b4e1db030f.tar.xz
[chore] Add interaction filter to complement existing visibility filter (#3111)
* [chore] Add interaction filter to complement existing visibility filter * pass in ptr to visibility and interaction filters to Processor{} to ensure shared * use int constants for for match type, cache db calls in filterctx * function name typo :innocent: --------- Co-authored-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/processing/workers')
-rw-r--r--internal/processing/workers/fromfediapi_test.go192
-rw-r--r--internal/processing/workers/surface.go2
-rw-r--r--internal/processing/workers/surfacenotify_test.go2
-rw-r--r--internal/processing/workers/surfacetimeline.go4
-rw-r--r--internal/processing/workers/workers.go4
-rw-r--r--internal/processing/workers/workers_test.go14
6 files changed, 130 insertions, 88 deletions
diff --git a/internal/processing/workers/fromfediapi_test.go b/internal/processing/workers/fromfediapi_test.go
index 705795af4..f08f059ea 100644
--- a/internal/processing/workers/fromfediapi_test.go
+++ b/internal/processing/workers/fromfediapi_test.go
@@ -45,8 +45,12 @@ func (suite *FromFediAPITestSuite) TestProcessFederationAnnounce() {
testStructs := suite.SetupTestStructs()
defer suite.TearDownTestStructs(testStructs)
- boostedStatus := suite.testStatuses["local_account_1_status_1"]
- boostingAccount := suite.testAccounts["remote_account_1"]
+ boostedStatus := &gtsmodel.Status{}
+ *boostedStatus = *suite.testStatuses["local_account_1_status_1"]
+
+ boostingAccount := &gtsmodel.Account{}
+ *boostingAccount = *suite.testAccounts["remote_account_1"]
+
announceStatus := &gtsmodel.Status{}
announceStatus.URI = "https://example.org/some-announce-uri"
announceStatus.BoostOfURI = boostedStatus.URI
@@ -64,13 +68,25 @@ func (suite *FromFediAPITestSuite) TestProcessFederationAnnounce() {
Receiving: suite.testAccounts["local_account_1"],
Requesting: boostingAccount,
})
- suite.NoError(err)
+ if err != nil {
+ suite.FailNow(err.Error())
+ }
- // side effects should be triggered
+ // Wait for side effects to trigger:
// 1. status should have an ID, and be in the database
- suite.NotEmpty(announceStatus.ID)
- _, err = testStructs.State.DB.GetStatusByID(context.Background(), announceStatus.ID)
- suite.NoError(err)
+ if !testrig.WaitFor(func() bool {
+ if announceStatus.ID == "" {
+ return false
+ }
+
+ _, err = testStructs.State.DB.GetStatusByID(
+ context.Background(),
+ announceStatus.ID,
+ )
+ return err == nil
+ }) {
+ suite.FailNow("timed out waiting for announce to be in the database")
+ }
// 2. a notification should exist for the announce
where := []db.Where{
@@ -89,78 +105,89 @@ func (suite *FromFediAPITestSuite) TestProcessFederationAnnounce() {
suite.False(*notif.Read)
}
-// Todo: fix this test up in interaction policies PR.
-// func (suite *FromFediAPITestSuite) TestProcessReplyMention() {
-// testStructs := suite.SetupTestStructs()
-// defer suite.TearDownTestStructs(testStructs)
-
-// repliedAccount := suite.testAccounts["local_account_1"]
-// repliedStatus := suite.testStatuses["local_account_1_status_1"]
-// replyingAccount := suite.testAccounts["remote_account_1"]
-
-// // Set the replyingAccount's last fetched_at
-// // date to something recent so no refresh is attempted,
-// // and ensure it isn't a suspended account.
-// replyingAccount.FetchedAt = time.Now()
-// replyingAccount.SuspendedAt = time.Time{}
-// replyingAccount.SuspensionOrigin = ""
-// err := testStructs.State.DB.UpdateAccount(context.Background(),
-// replyingAccount,
-// "fetched_at",
-// "suspended_at",
-// "suspension_origin",
-// )
-// suite.NoError(err)
-
-// // Get replying statusable to use from remote test statuses.
-// const replyingURI = "http://fossbros-anonymous.io/users/foss_satan/statuses/106221634728637552"
-// replyingStatusable := testrig.NewTestFediStatuses()[replyingURI]
-// ap.AppendInReplyTo(replyingStatusable, testrig.URLMustParse(repliedStatus.URI))
-
-// // Open a websocket stream to later test the streamed status reply.
-// wssStream, errWithCode := testStructs.Processor.Stream().Open(context.Background(), repliedAccount, stream.TimelineHome)
-// suite.NoError(errWithCode)
-
-// // Send the replied status off to the fedi worker to be further processed.
-// err = testStructs.Processor.Workers().ProcessFromFediAPI(context.Background(), &messages.FromFediAPI{
-// APObjectType: ap.ObjectNote,
-// APActivityType: ap.ActivityCreate,
-// APObject: replyingStatusable,
-// Receiving: repliedAccount,
-// Requesting: replyingAccount,
-// })
-// suite.NoError(err)
-
-// // side effects should be triggered
-// // 1. status should be in the database
-// replyingStatus, err := testStructs.State.DB.GetStatusByURI(context.Background(), replyingURI)
-// suite.NoError(err)
-
-// // 2. a notification should exist for the mention
-// var notif gtsmodel.Notification
-// err = testStructs.State.DB.GetWhere(context.Background(), []db.Where{
-// {Key: "status_id", Value: replyingStatus.ID},
-// }, &notif)
-// suite.NoError(err)
-// suite.Equal(gtsmodel.NotificationMention, notif.NotificationType)
-// suite.Equal(replyingStatus.InReplyToAccountID, notif.TargetAccountID)
-// suite.Equal(replyingStatus.AccountID, notif.OriginAccountID)
-// suite.Equal(replyingStatus.ID, notif.StatusID)
-// suite.False(*notif.Read)
-
-// ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
-// msg, ok := wssStream.Recv(ctx)
-// suite.True(ok)
-
-// suite.Equal(stream.EventTypeNotification, msg.Event)
-// suite.NotEmpty(msg.Payload)
-// suite.EqualValues([]string{stream.TimelineHome}, msg.Stream)
-// notifStreamed := &apimodel.Notification{}
-// err = json.Unmarshal([]byte(msg.Payload), notifStreamed)
-// suite.NoError(err)
-// suite.Equal("mention", notifStreamed.Type)
-// suite.Equal(replyingAccount.ID, notifStreamed.Account.ID)
-// }
+func (suite *FromFediAPITestSuite) TestProcessReplyMention() {
+ testStructs := suite.SetupTestStructs()
+ defer suite.TearDownTestStructs(testStructs)
+
+ repliedAccount := &gtsmodel.Account{}
+ *repliedAccount = *suite.testAccounts["local_account_1"]
+
+ repliedStatus := &gtsmodel.Status{}
+ *repliedStatus = *suite.testStatuses["local_account_1_status_1"]
+
+ replyingAccount := &gtsmodel.Account{}
+ *replyingAccount = *suite.testAccounts["remote_account_1"]
+
+ // Set the replyingAccount's last fetched_at
+ // date to something recent so no refresh is attempted,
+ // and ensure it isn't a suspended account.
+ replyingAccount.FetchedAt = time.Now()
+ replyingAccount.SuspendedAt = time.Time{}
+ replyingAccount.SuspensionOrigin = ""
+ err := testStructs.State.DB.UpdateAccount(context.Background(),
+ replyingAccount,
+ "fetched_at",
+ "suspended_at",
+ "suspension_origin",
+ )
+ suite.NoError(err)
+
+ // Get replying statusable to use from remote test statuses.
+ const replyingURI = "http://fossbros-anonymous.io/users/foss_satan/statuses/106221634728637552"
+ replyingStatusable := testrig.NewTestFediStatuses()[replyingURI]
+ ap.AppendInReplyTo(replyingStatusable, testrig.URLMustParse(repliedStatus.URI))
+
+ // Open a websocket stream to later test the streamed status reply.
+ wssStream, errWithCode := testStructs.Processor.Stream().Open(context.Background(), repliedAccount, stream.TimelineHome)
+ suite.NoError(errWithCode)
+
+ // Send the replied status off to the fedi worker to be further processed.
+ err = testStructs.Processor.Workers().ProcessFromFediAPI(context.Background(), &messages.FromFediAPI{
+ APObjectType: ap.ObjectNote,
+ APActivityType: ap.ActivityCreate,
+ APObject: replyingStatusable,
+ Receiving: repliedAccount,
+ Requesting: replyingAccount,
+ })
+ if err != nil {
+ suite.FailNow(err.Error())
+ }
+
+ // Wait for side effects to trigger:
+ // 1. status should be in the database
+ var replyingStatus *gtsmodel.Status
+ if !testrig.WaitFor(func() bool {
+ replyingStatus, err = testStructs.State.DB.GetStatusByURI(context.Background(), replyingURI)
+ return err == nil
+ }) {
+ suite.FailNow("timed out waiting for replying status to be in the database")
+ }
+
+ // 2. a notification should exist for the mention
+ var notif gtsmodel.Notification
+ err = testStructs.State.DB.GetWhere(context.Background(), []db.Where{
+ {Key: "status_id", Value: replyingStatus.ID},
+ }, &notif)
+ suite.NoError(err)
+ suite.Equal(gtsmodel.NotificationMention, notif.NotificationType)
+ suite.Equal(replyingStatus.InReplyToAccountID, notif.TargetAccountID)
+ suite.Equal(replyingStatus.AccountID, notif.OriginAccountID)
+ suite.Equal(replyingStatus.ID, notif.StatusID)
+ suite.False(*notif.Read)
+
+ ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
+ msg, ok := wssStream.Recv(ctx)
+ suite.True(ok)
+
+ suite.Equal(stream.EventTypeNotification, msg.Event)
+ suite.NotEmpty(msg.Payload)
+ suite.EqualValues([]string{stream.TimelineHome}, msg.Stream)
+ notifStreamed := &apimodel.Notification{}
+ err = json.Unmarshal([]byte(msg.Payload), notifStreamed)
+ suite.NoError(err)
+ suite.Equal("mention", notifStreamed.Type)
+ suite.Equal(replyingAccount.ID, notifStreamed.Account.ID)
+}
func (suite *FromFediAPITestSuite) TestProcessFave() {
testStructs := suite.SetupTestStructs()
@@ -305,8 +332,11 @@ func (suite *FromFediAPITestSuite) TestProcessAccountDelete() {
ctx := context.Background()
- deletedAccount := suite.testAccounts["remote_account_1"]
- receivingAccount := suite.testAccounts["local_account_1"]
+ deletedAccount := &gtsmodel.Account{}
+ *deletedAccount = *suite.testAccounts["remote_account_1"]
+
+ receivingAccount := &gtsmodel.Account{}
+ *receivingAccount = *suite.testAccounts["local_account_1"]
// before doing the delete....
// make local_account_1 and remote_account_1 into mufos
diff --git a/internal/processing/workers/surface.go b/internal/processing/workers/surface.go
index 1a7dbbfe5..4f6597b9a 100644
--- a/internal/processing/workers/surface.go
+++ b/internal/processing/workers/surface.go
@@ -36,7 +36,7 @@ type Surface struct {
State *state.State
Converter *typeutils.Converter
Stream *stream.Processor
- Filter *visibility.Filter
+ VisFilter *visibility.Filter
EmailSender email.Sender
Conversations *conversations.Processor
}
diff --git a/internal/processing/workers/surfacenotify_test.go b/internal/processing/workers/surfacenotify_test.go
index 937ddeca2..876f69933 100644
--- a/internal/processing/workers/surfacenotify_test.go
+++ b/internal/processing/workers/surfacenotify_test.go
@@ -42,7 +42,7 @@ func (suite *SurfaceNotifyTestSuite) TestSpamNotifs() {
State: testStructs.State,
Converter: testStructs.TypeConverter,
Stream: testStructs.Processor.Stream(),
- Filter: visibility.NewFilter(testStructs.State),
+ VisFilter: visibility.NewFilter(testStructs.State),
EmailSender: testStructs.EmailSender,
Conversations: testStructs.Processor.Conversations(),
}
diff --git a/internal/processing/workers/surfacetimeline.go b/internal/processing/workers/surfacetimeline.go
index 8ac8293ed..7bd0a51c6 100644
--- a/internal/processing/workers/surfacetimeline.go
+++ b/internal/processing/workers/surfacetimeline.go
@@ -109,7 +109,7 @@ func (s *Surface) timelineAndNotifyStatusForFollowers(
// If it's not timelineable, we can just stop early, since lists
// are prettymuch subsets of the home timeline, so if it shouldn't
// appear there, it shouldn't appear in lists either.
- timelineable, err := s.Filter.StatusHomeTimelineable(
+ timelineable, err := s.VisFilter.StatusHomeTimelineable(
ctx, follow.Account, status,
)
if err != nil {
@@ -482,7 +482,7 @@ func (s *Surface) timelineStatusUpdateForFollowers(
// If it's not timelineable, we can just stop early, since lists
// are prettymuch subsets of the home timeline, so if it shouldn't
// appear there, it shouldn't appear in lists either.
- timelineable, err := s.Filter.StatusHomeTimelineable(
+ timelineable, err := s.VisFilter.StatusHomeTimelineable(
ctx, follow.Account, status,
)
if err != nil {
diff --git a/internal/processing/workers/workers.go b/internal/processing/workers/workers.go
index c7f67b025..04010a92e 100644
--- a/internal/processing/workers/workers.go
+++ b/internal/processing/workers/workers.go
@@ -40,7 +40,7 @@ func New(
state *state.State,
federator *federation.Federator,
converter *typeutils.Converter,
- filter *visibility.Filter,
+ visFilter *visibility.Filter,
emailSender email.Sender,
account *account.Processor,
media *media.Processor,
@@ -61,7 +61,7 @@ func New(
State: state,
Converter: converter,
Stream: stream,
- Filter: filter,
+ VisFilter: visFilter,
EmailSender: emailSender,
Conversations: conversations,
}
diff --git a/internal/processing/workers/workers_test.go b/internal/processing/workers/workers_test.go
index 3093fd93a..65ed3f6b7 100644
--- a/internal/processing/workers/workers_test.go
+++ b/internal/processing/workers/workers_test.go
@@ -23,6 +23,7 @@ import (
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/cleaner"
"github.com/superseriousbusiness/gotosocial/internal/email"
+ "github.com/superseriousbusiness/gotosocial/internal/filter/interaction"
"github.com/superseriousbusiness/gotosocial/internal/filter/visibility"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
@@ -160,7 +161,18 @@ func (suite *WorkersTestSuite) SetupTestStructs() *TestStructs {
oauthServer := testrig.NewTestOauthServer(db)
emailSender := testrig.NewEmailSender("../../../web/template/", nil)
- processor := processing.NewProcessor(cleaner.New(&state), typeconverter, federator, oauthServer, mediaManager, &state, emailSender)
+ processor := processing.NewProcessor(
+ cleaner.New(&state),
+ typeconverter,
+ federator,
+ oauthServer,
+ mediaManager,
+ &state,
+ emailSender,
+ visibility.NewFilter(&state),
+ interaction.NewFilter(&state),
+ )
+
testrig.StartWorkers(&state, processor.Workers())
testrig.StandardDBSetup(db, suite.testAccounts)