summaryrefslogtreecommitdiff
path: root/internal/webpush
diff options
context:
space:
mode:
Diffstat (limited to 'internal/webpush')
-rw-r--r--internal/webpush/realsender.go57
-rw-r--r--internal/webpush/realsender_test.go10
-rw-r--r--internal/webpush/sender.go12
3 files changed, 36 insertions, 43 deletions
diff --git a/internal/webpush/realsender.go b/internal/webpush/realsender.go
index 075927095..99472c815 100644
--- a/internal/webpush/realsender.go
+++ b/internal/webpush/realsender.go
@@ -29,7 +29,6 @@ import (
apimodel "code.superseriousbusiness.org/gotosocial/internal/api/model"
"code.superseriousbusiness.org/gotosocial/internal/config"
- "code.superseriousbusiness.org/gotosocial/internal/filter/usermute"
"code.superseriousbusiness.org/gotosocial/internal/gtserror"
"code.superseriousbusiness.org/gotosocial/internal/gtsmodel"
"code.superseriousbusiness.org/gotosocial/internal/log"
@@ -49,25 +48,23 @@ type realSender struct {
func (r *realSender) Send(
ctx context.Context,
- notification *gtsmodel.Notification,
- filters []*gtsmodel.Filter,
- mutes *usermute.CompiledUserMuteList,
+ notif *gtsmodel.Notification,
+ apiNotif *apimodel.Notification,
) error {
+ // Get notification target.
+ target := notif.TargetAccount
+
// Load subscriptions.
- subscriptions, err := r.state.DB.GetWebPushSubscriptionsByAccountID(ctx, notification.TargetAccountID)
+ subscriptions, err := r.state.DB.GetWebPushSubscriptionsByAccountID(ctx, target.ID)
if err != nil {
- return gtserror.Newf(
- "error getting Web Push subscriptions for account %s: %w",
- notification.TargetAccountID,
- err,
- )
+ return gtserror.Newf("error getting Web Push subscriptions for account %s: %w", target.URI, err)
}
// Subscriptions we're actually going to send to.
relevantSubscriptions := slices.DeleteFunc(
subscriptions,
func(subscription *gtsmodel.WebPushSubscription) bool {
- return r.shouldSkipSubscription(ctx, notification, subscription)
+ return r.shouldSkipSubscription(ctx, notif, subscription)
},
)
if len(relevantSubscriptions) == 0 {
@@ -80,31 +77,28 @@ func (r *realSender) Send(
return gtserror.Newf("error getting VAPID key pair: %w", err)
}
- // Get target account settings.
- targetAccountSettings, err := r.state.DB.GetAccountSettings(ctx, notification.TargetAccountID)
- if err != nil {
- return gtserror.Newf("error getting settings for account %s: %w", notification.TargetAccountID, err)
- }
+ if target.Settings == nil {
+ // Ensure the target account's settings are populated.
+ settings, err := r.state.DB.GetAccountSettings(ctx, target.ID)
+ if err != nil {
+ return gtserror.Newf("error getting settings for account %s: %w", target.URI, err)
+ }
- // Get API representations of notification and accounts involved.
- 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)
+ // Set target's settings.
+ target.Settings = settings
}
// Queue up a .Send() call for each relevant subscription.
for _, subscription := range relevantSubscriptions {
r.state.Workers.WebPush.Queue.Push(func(ctx context.Context) {
- if err := r.sendToSubscription(
- ctx,
+ if err := r.sendToSubscription(ctx,
vapidKeyPair,
- targetAccountSettings,
+ target.Settings,
subscription,
- notification,
- apiNotification,
+ notif,
+ apiNotif,
); err != nil {
- log.Errorf(
- ctx,
+ log.Errorf(ctx,
"error sending Web Push notification for subscription with token ID %s: %v",
subscription.TokenID,
err,
@@ -137,8 +131,7 @@ func (r *realSender) shouldSkipSubscription(
// Allow if the subscription account follows the notifying account.
isFollowing, err := r.state.DB.IsFollowing(ctx, subscription.AccountID, notification.OriginAccountID)
if err != nil {
- log.Errorf(
- ctx,
+ log.Errorf(ctx,
"error checking whether account %s follows account %s: %v",
subscription.AccountID,
notification.OriginAccountID,
@@ -152,8 +145,7 @@ func (r *realSender) shouldSkipSubscription(
// Allow if the notifying account follows the subscription account.
isFollowing, err := r.state.DB.IsFollowing(ctx, notification.OriginAccountID, subscription.AccountID)
if err != nil {
- log.Errorf(
- ctx,
+ log.Errorf(ctx,
"error checking whether account %s follows account %s: %v",
notification.OriginAccountID,
subscription.AccountID,
@@ -168,8 +160,7 @@ func (r *realSender) shouldSkipSubscription(
return true
default:
- log.Errorf(
- ctx,
+ log.Errorf(ctx,
"unknown Web Push notification policy for subscription with token ID %s: %d",
subscription.TokenID,
subscription.Policy,
diff --git a/internal/webpush/realsender_test.go b/internal/webpush/realsender_test.go
index bddcbbc28..a404c166f 100644
--- a/internal/webpush/realsender_test.go
+++ b/internal/webpush/realsender_test.go
@@ -32,6 +32,7 @@ import (
"code.superseriousbusiness.org/gotosocial/internal/email"
"code.superseriousbusiness.org/gotosocial/internal/federation"
"code.superseriousbusiness.org/gotosocial/internal/filter/interaction"
+ "code.superseriousbusiness.org/gotosocial/internal/filter/mutes"
"code.superseriousbusiness.org/gotosocial/internal/filter/visibility"
"code.superseriousbusiness.org/gotosocial/internal/gtsmodel"
"code.superseriousbusiness.org/gotosocial/internal/media"
@@ -123,6 +124,7 @@ func (suite *RealSenderStandardTestSuite) SetupTest() {
suite.emailSender,
suite.webPushSender,
visibility.NewFilter(&suite.state),
+ mutes.NewFilter(&suite.state),
interaction.NewFilter(&suite.state),
)
testrig.StartWorkers(&suite.state, suite.processor.Workers())
@@ -188,8 +190,14 @@ func (suite *RealSenderStandardTestSuite) simulatePushNotification(
}, nil
}
+ apiNotif, err := suite.typeconverter.NotificationToAPINotification(ctx, notification, nil)
+ suite.NoError(err)
+
// Send the push notification.
- sendError := suite.webPushSender.Send(ctx, notification, nil, nil)
+ sendError := suite.webPushSender.Send(ctx,
+ notification,
+ apiNotif,
+ )
// Wait for it to be sent or for the context to time out.
bodyClosed := false
diff --git a/internal/webpush/sender.go b/internal/webpush/sender.go
index b7bb75d41..bdc00db1b 100644
--- a/internal/webpush/sender.go
+++ b/internal/webpush/sender.go
@@ -21,7 +21,7 @@ import (
"context"
"net/http"
- "code.superseriousbusiness.org/gotosocial/internal/filter/usermute"
+ apimodel "code.superseriousbusiness.org/gotosocial/internal/api/model"
"code.superseriousbusiness.org/gotosocial/internal/gtsmodel"
"code.superseriousbusiness.org/gotosocial/internal/httpclient"
"code.superseriousbusiness.org/gotosocial/internal/state"
@@ -31,14 +31,8 @@ import (
// Sender can send Web Push notifications.
type Sender interface {
- // Send queues up a notification for delivery to
- // all of an account's Web Push subscriptions.
- Send(
- ctx context.Context,
- notification *gtsmodel.Notification,
- filters []*gtsmodel.Filter,
- mutes *usermute.CompiledUserMuteList,
- ) error
+ // Send queues up a notification for delivery to all of an account's Web Push subscriptions.
+ Send(ctx context.Context, notif *gtsmodel.Notification, apiNotif *apimodel.Notification) error
}
// NewSender creates a new sender from an HTTP client, DB, and worker pool.