Web Push: add policy to API

This commit is contained in:
Vyr Cossont 2025-01-31 12:34:20 -08:00
commit c0e53662cf
10 changed files with 121 additions and 4 deletions

View file

@ -24,6 +24,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/id"
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
)
// CreateOrReplace creates a Web Push subscription for the given access token,
@ -54,6 +55,7 @@ func (p *Processor) CreateOrReplace(
Auth: request.Subscription.Keys.Auth,
P256dh: request.Subscription.Keys.P256dh,
NotificationFlags: alertsToNotificationFlags(request.Data.Alerts),
Policy: typeutils.APIWebPushNotificationPolicyToWebPushNotificationPolicy(*request.Data.Policy),
}
if err := p.state.DB.PutWebPushSubscription(ctx, subscription); err != nil {

View file

@ -24,6 +24,7 @@ import (
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
)
// Update updates the Web Push subscription for the given access token.
@ -50,10 +51,13 @@ func (p *Processor) Update(
// Update it.
subscription.NotificationFlags = alertsToNotificationFlags(request.Data.Alerts)
subscription.Policy = typeutils.APIWebPushNotificationPolicyToWebPushNotificationPolicy(*request.Data.Policy)
if err = p.state.DB.UpdateWebPushSubscription(
ctx,
subscription,
"notification_flags",
"policy",
); err != nil {
err := gtserror.Newf("couldn't update Web Push subscription for token ID %s: %w", tokenID, err)
return nil, gtserror.NewErrorInternalError(err)