bigbuffet-rw/app/soapbox/reducers/push_notifications.js

38 lines
1 KiB
JavaScript
Raw Normal View History

2020-03-27 13:59:38 -07:00
import { SET_BROWSER_SUPPORT, SET_SUBSCRIPTION, CLEAR_SUBSCRIPTION, SET_ALERTS } from '../actions/push_notifications';
2021-09-12 09:25:44 -07:00
import { Map as ImmutableMap } from 'immutable';
2020-03-27 13:59:38 -07:00
2021-09-12 09:25:44 -07:00
const initialState = ImmutableMap({
2020-03-27 13:59:38 -07:00
subscription: null,
2021-09-12 09:25:44 -07:00
alerts: new ImmutableMap({
2020-03-27 13:59:38 -07:00
follow: false,
follow_request: false,
2020-03-27 13:59:38 -07:00
favourite: false,
reblog: false,
mention: false,
poll: false,
}),
isSubscribed: false,
browserSupport: false,
});
export default function push_subscriptions(state = initialState, action) {
switch(action.type) {
case SET_SUBSCRIPTION:
return state
2021-09-12 09:25:44 -07:00
.set('subscription', new ImmutableMap({
2020-03-27 13:59:38 -07:00
id: action.subscription.id,
endpoint: action.subscription.endpoint,
}))
2021-09-12 09:25:44 -07:00
.set('alerts', new ImmutableMap(action.subscription.alerts))
2020-03-27 13:59:38 -07:00
.set('isSubscribed', true);
case SET_BROWSER_SUPPORT:
return state.set('browserSupport', action.value);
case CLEAR_SUBSCRIPTION:
return initialState;
case SET_ALERTS:
return state.setIn(action.path, action.value);
default:
return state;
}
2021-08-03 12:22:51 -07:00
}