logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

push_notifications.js (1509B)


  1. import { STORE_HYDRATE } from '../actions/store';
  2. import { SET_BROWSER_SUPPORT, SET_SUBSCRIPTION, CLEAR_SUBSCRIPTION, SET_ALERTS } from '../actions/push_notifications';
  3. import Immutable from 'immutable';
  4. const initialState = Immutable.Map({
  5. subscription: null,
  6. alerts: new Immutable.Map({
  7. follow: false,
  8. favourite: false,
  9. reblog: false,
  10. mention: false,
  11. }),
  12. isSubscribed: false,
  13. browserSupport: false,
  14. });
  15. export default function push_subscriptions(state = initialState, action) {
  16. switch(action.type) {
  17. case STORE_HYDRATE: {
  18. const push_subscription = action.state.get('push_subscription');
  19. if (push_subscription) {
  20. return state
  21. .set('subscription', new Immutable.Map({
  22. id: push_subscription.get('id'),
  23. endpoint: push_subscription.get('endpoint'),
  24. }))
  25. .set('alerts', push_subscription.get('alerts') || initialState.get('alerts'))
  26. .set('isSubscribed', true);
  27. }
  28. return state;
  29. }
  30. case SET_SUBSCRIPTION:
  31. return state
  32. .set('subscription', new Immutable.Map({
  33. id: action.subscription.id,
  34. endpoint: action.subscription.endpoint,
  35. }))
  36. .set('alerts', new Immutable.Map(action.subscription.alerts))
  37. .set('isSubscribed', true);
  38. case SET_BROWSER_SUPPORT:
  39. return state.set('browserSupport', action.value);
  40. case CLEAR_SUBSCRIPTION:
  41. return initialState;
  42. case SET_ALERTS:
  43. return state.setIn(action.path, action.value);
  44. default:
  45. return state;
  46. }
  47. };