2017-07-13 22:15:32 +02:00
|
|
|
import Immutable from 'immutable';
|
|
|
|
|
2023-05-28 16:38:10 +02:00
|
|
|
import { SET_BROWSER_SUPPORT, SET_SUBSCRIPTION, CLEAR_SUBSCRIPTION, SET_ALERTS } from 'flavours/glitch/actions/push_notifications';
|
|
|
|
import { STORE_HYDRATE } from 'flavours/glitch/actions/store';
|
|
|
|
|
2017-07-13 22:15:32 +02:00
|
|
|
const initialState = Immutable.Map({
|
|
|
|
subscription: null,
|
|
|
|
alerts: new Immutable.Map({
|
|
|
|
follow: false,
|
2019-12-01 17:25:29 +01:00
|
|
|
follow_request: false,
|
2017-07-13 22:15:32 +02:00
|
|
|
favourite: false,
|
|
|
|
reblog: false,
|
|
|
|
mention: false,
|
2019-03-13 19:29:54 +01:00
|
|
|
poll: false,
|
2017-07-13 22:15:32 +02:00
|
|
|
}),
|
|
|
|
isSubscribed: false,
|
|
|
|
browserSupport: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
export default function push_subscriptions(state = initialState, action) {
|
|
|
|
switch(action.type) {
|
|
|
|
case STORE_HYDRATE: {
|
|
|
|
const push_subscription = action.state.get('push_subscription');
|
|
|
|
|
|
|
|
if (push_subscription) {
|
|
|
|
return state
|
|
|
|
.set('subscription', new Immutable.Map({
|
|
|
|
id: push_subscription.get('id'),
|
|
|
|
endpoint: push_subscription.get('endpoint'),
|
|
|
|
}))
|
|
|
|
.set('alerts', push_subscription.get('alerts') || initialState.get('alerts'))
|
|
|
|
.set('isSubscribed', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
case SET_SUBSCRIPTION:
|
|
|
|
return state
|
|
|
|
.set('subscription', new Immutable.Map({
|
|
|
|
id: action.subscription.id,
|
|
|
|
endpoint: action.subscription.endpoint,
|
|
|
|
}))
|
|
|
|
.set('alerts', new Immutable.Map(action.subscription.alerts))
|
|
|
|
.set('isSubscribed', true);
|
|
|
|
case SET_BROWSER_SUPPORT:
|
|
|
|
return state.set('browserSupport', action.value);
|
|
|
|
case CLEAR_SUBSCRIPTION:
|
|
|
|
return initialState;
|
2017-12-30 18:45:01 +01:00
|
|
|
case SET_ALERTS:
|
2018-01-09 16:48:14 +01:00
|
|
|
return state.setIn(action.path, action.value);
|
2017-07-13 22:15:32 +02:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
2023-02-03 20:52:07 +01:00
|
|
|
}
|