2022-06-23 15:33:23 -07:00
|
|
|
import { Map as ImmutableMap, Record as ImmutableRecord } from 'immutable';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2022-11-15 12:50:11 -08:00
|
|
|
import { SET_BROWSER_SUPPORT, SET_SUBSCRIPTION, CLEAR_SUBSCRIPTION, SET_ALERTS } from '../actions/push-notifications';
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2022-06-23 15:33:23 -07:00
|
|
|
import type { AnyAction } from 'redux';
|
|
|
|
|
|
|
|
const SubscriptionRecord = ImmutableRecord({
|
|
|
|
id: '',
|
|
|
|
endpoint: '',
|
|
|
|
});
|
|
|
|
|
|
|
|
const ReducerRecord = ImmutableRecord({
|
|
|
|
subscription: null as Subscription | null,
|
|
|
|
alerts: ImmutableMap<string, boolean>({
|
2021-11-18 13:11:50 -08:00
|
|
|
follow: true,
|
|
|
|
follow_request: true,
|
|
|
|
favourite: true,
|
|
|
|
reblog: true,
|
|
|
|
mention: true,
|
|
|
|
poll: true,
|
2020-03-27 13:59:38 -07:00
|
|
|
}),
|
|
|
|
isSubscribed: false,
|
|
|
|
browserSupport: false,
|
|
|
|
});
|
|
|
|
|
2022-06-23 15:33:23 -07:00
|
|
|
type Subscription = ReturnType<typeof SubscriptionRecord>;
|
|
|
|
|
|
|
|
export default function push_subscriptions(state = ReducerRecord(), action: AnyAction) {
|
2022-05-11 10:40:34 -07:00
|
|
|
switch (action.type) {
|
2022-05-11 14:06:35 -07:00
|
|
|
case SET_SUBSCRIPTION:
|
|
|
|
return state
|
2022-06-23 15:33:23 -07:00
|
|
|
.set('subscription', SubscriptionRecord({
|
2022-05-11 14:06:35 -07:00
|
|
|
id: action.subscription.id,
|
|
|
|
endpoint: action.subscription.endpoint,
|
|
|
|
}))
|
2022-06-23 15:33:23 -07:00
|
|
|
.set('alerts', ImmutableMap(action.subscription.alerts))
|
2022-05-11 14:06:35 -07:00
|
|
|
.set('isSubscribed', true);
|
|
|
|
case SET_BROWSER_SUPPORT:
|
|
|
|
return state.set('browserSupport', action.value);
|
|
|
|
case CLEAR_SUBSCRIPTION:
|
2022-06-23 15:33:23 -07:00
|
|
|
return ReducerRecord();
|
2022-05-11 14:06:35 -07:00
|
|
|
case SET_ALERTS:
|
|
|
|
return state.setIn(action.path, action.value);
|
|
|
|
default:
|
|
|
|
return state;
|
2020-03-27 13:59:38 -07:00
|
|
|
}
|
2021-08-03 12:22:51 -07:00
|
|
|
}
|