From d89f3ec8f1535632063f08e047e308b74e515b79 Mon Sep 17 00:00:00 2001 From: Vyr Cossont Date: Thu, 23 Jan 2025 10:00:55 -0800 Subject: [PATCH] webpush.Sender: take type converter as ctor param --- cmd/gotosocial/action/server/server.go | 2 +- internal/webpush/realsender.go | 8 ++++---- internal/webpush/realsender_test.go | 1 + internal/webpush/sender.go | 4 +++- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cmd/gotosocial/action/server/server.go b/cmd/gotosocial/action/server/server.go index 3aef73154..7a374fbcd 100644 --- a/cmd/gotosocial/action/server/server.go +++ b/cmd/gotosocial/action/server/server.go @@ -254,7 +254,7 @@ var Start action.GTSAction = func(ctx context.Context) error { } // Create a Web Push notification sender. - webPushSender := webpush.NewSender(client, state) + webPushSender := webpush.NewSender(client, state, typeConverter) // Initialize both home / list timelines. state.Timelines.Home = timeline.NewManager( diff --git a/internal/webpush/realsender.go b/internal/webpush/realsender.go index 46137bc9e..8b3a1bd66 100644 --- a/internal/webpush/realsender.go +++ b/internal/webpush/realsender.go @@ -44,16 +44,16 @@ import ( type realSender struct { httpClient *http.Client state *state.State - tc *typeutils.Converter + converter *typeutils.Converter } // NewRealSender creates a Sender from an http.Client instead of an httpclient.Client. // This should only be used by NewSender and in tests. -func NewRealSender(httpClient *http.Client, state *state.State) Sender { +func NewRealSender(httpClient *http.Client, state *state.State, converter *typeutils.Converter) Sender { return &realSender{ httpClient: httpClient, state: state, - tc: typeutils.NewConverter(state), + converter: converter, } } @@ -110,7 +110,7 @@ func (r *realSender) Send( } // Get API representations of notification and accounts involved. - apiNotification, err := r.tc.NotificationToAPINotification(ctx, notification, filters, mutes) + apiNotification, err := r.converter.NotificationToAPINotification(ctx, notification, filters, mutes) if err != nil { return gtserror.Newf("error converting notification %s to API representation: %w", notification.ID, err) } diff --git a/internal/webpush/realsender_test.go b/internal/webpush/realsender_test.go index 268576978..c94bbbb8e 100644 --- a/internal/webpush/realsender_test.go +++ b/internal/webpush/realsender_test.go @@ -125,6 +125,7 @@ func (suite *RealSenderStandardTestSuite) SetupTest() { Transport: suite, }, &suite.state, + suite.typeconverter, ) suite.processor = processing.NewProcessor( diff --git a/internal/webpush/sender.go b/internal/webpush/sender.go index de0f4b04c..5331f049a 100644 --- a/internal/webpush/sender.go +++ b/internal/webpush/sender.go @@ -25,6 +25,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/httpclient" "github.com/superseriousbusiness/gotosocial/internal/state" + "github.com/superseriousbusiness/gotosocial/internal/typeutils" ) // Sender can send Web Push notifications. @@ -39,7 +40,7 @@ type Sender interface { } // NewSender creates a new sender from an HTTP client, DB, and worker pool. -func NewSender(httpClient *httpclient.Client, state *state.State) Sender { +func NewSender(httpClient *httpclient.Client, state *state.State, converter *typeutils.Converter) Sender { return NewRealSender( &http.Client{ Transport: >sHTTPClientRoundTripper{ @@ -48,5 +49,6 @@ func NewSender(httpClient *httpclient.Client, state *state.State) Sender { // Other fields are already set on the http.Client inside the httpclient.Client. }, state, + converter, ) }