Merge branch 'push-fixes' into 'main'

Fix sending PushSubscription object to the API

See merge request soapbox-pub/soapbox!3139
This commit is contained in:
Alex Gleason 2024-10-07 20:32:08 +00:00
commit 998db8477b
2 changed files with 11 additions and 3 deletions

View File

@ -45,7 +45,7 @@ const unsubscribe = ({ registration, subscription }: {
const sendSubscriptionToBackend = (subscription: PushSubscription, me: Me) => const sendSubscriptionToBackend = (subscription: PushSubscription, me: Me) =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) => {
const alerts = getState().push_notifications.alerts.toJS(); const alerts = getState().push_notifications.alerts.toJS();
const params = { subscription, data: { alerts } }; const params = { subscription: subscription.toJSON(), data: { alerts } };
if (me) { if (me) {
const data = pushNotificationsSetting.get(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 // Last one checks for payload support: https://web-push-book.gauntface.com/chapter-06/01-non-standards-browsers/#no-payload

View File

@ -18,7 +18,15 @@ const PUSH_SUBSCRIPTION_DELETE_FAIL = 'PUSH_SUBSCRIPTION_DELETE_FAIL';
import type { AppDispatch, RootState } from 'soapbox/store'; import type { AppDispatch, RootState } from 'soapbox/store';
const createPushSubscription = (params: Record<string, any>) => interface CreatePushSubscriptionParams {
subscription: PushSubscriptionJSON;
data?: {
alerts?: Record<string, boolean>;
policy?: 'all' | 'followed' | 'follower' | 'none';
};
}
const createPushSubscription = (params: CreatePushSubscriptionParams) =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) => {
dispatch({ type: PUSH_SUBSCRIPTION_CREATE_REQUEST, params }); dispatch({ type: PUSH_SUBSCRIPTION_CREATE_REQUEST, params });
return api(getState).post('/api/v1/push/subscription', params).then(({ data: subscription }) => return api(getState).post('/api/v1/push/subscription', params).then(({ data: subscription }) =>