summaryrefslogtreecommitdiff
path: root/internal/webpush/realsender.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/webpush/realsender.go')
-rw-r--r--internal/webpush/realsender.go57
1 files changed, 24 insertions, 33 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,