Fix sending PushSubscription object to the API
This commit is contained in:
parent
1de38c5ac7
commit
557f8c44c2
|
@ -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
|
||||||
|
|
|
@ -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 }) =>
|
||||||
|
|
Loading…
Reference in New Issue