diff --git a/src/actions/push-notifications/registerer.ts b/src/actions/push-notifications/registerer.ts index 48a0bc8fd..9937fd938 100644 --- a/src/actions/push-notifications/registerer.ts +++ b/src/actions/push-notifications/registerer.ts @@ -45,7 +45,7 @@ const unsubscribe = ({ registration, subscription }: { const sendSubscriptionToBackend = (subscription: PushSubscription, me: Me) => (dispatch: AppDispatch, getState: () => RootState) => { const alerts = getState().push_notifications.alerts.toJS(); - const params = { subscription, data: { alerts } }; + const params = { subscription: subscription.toJSON(), data: { alerts } }; if (me) { const data = pushNotificationsSetting.get(me); @@ -54,7 +54,7 @@ const sendSubscriptionToBackend = (subscription: PushSubscription, me: Me) => } } - return dispatch(createPushSubscription(params) as any); + return dispatch(createPushSubscription(params)); }; // Last one checks for payload support: https://web-push-book.gauntface.com/chapter-06/01-non-standards-browsers/#no-payload diff --git a/src/actions/push-subscriptions.ts b/src/actions/push-subscriptions.ts index b370c5045..19b047950 100644 --- a/src/actions/push-subscriptions.ts +++ b/src/actions/push-subscriptions.ts @@ -18,7 +18,15 @@ const PUSH_SUBSCRIPTION_DELETE_FAIL = 'PUSH_SUBSCRIPTION_DELETE_FAIL'; import type { AppDispatch, RootState } from 'soapbox/store'; -const createPushSubscription = (params: Record) => +interface CreatePushSubscriptionParams { + subscription: PushSubscriptionJSON; + data?: { + alerts?: Record; + policy?: 'all' | 'followed' | 'follower' | 'none'; + }; +} + +const createPushSubscription = (params: CreatePushSubscriptionParams) => (dispatch: AppDispatch, getState: () => RootState) => { dispatch({ type: PUSH_SUBSCRIPTION_CREATE_REQUEST, params }); return api(getState).post('/api/v1/push/subscription', params).then(({ data: subscription }) =>