You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // @flow
  2. import { APP_WILL_MOUNT } from '../app';
  3. import { ReducerRegistry, set } from '../base/redux';
  4. import { PersistenceRegistry } from '../base/storage';
  5. import {
  6. SET_CALENDAR_AUTHORIZATION,
  7. SET_CALENDAR_EVENTS
  8. } from './actionTypes';
  9. import { CALENDAR_ENABLED } from './constants';
  10. const DEFAULT_STATE = {
  11. /**
  12. * Note: If features/calendar-sync ever gets persisted, do not persist the
  13. * authorization value as it's needed to remain a runtime value to see if we
  14. * need to re-request the calendar permission from the user.
  15. */
  16. authorization: undefined,
  17. events: []
  18. };
  19. const STORE_NAME = 'features/calendar-sync';
  20. // XXX For legacy purposes, read any {@code knownDomains} persisted by the
  21. // feature calendar-sync.
  22. CALENDAR_ENABLED
  23. && PersistenceRegistry.register(STORE_NAME, {
  24. knownDomains: true
  25. });
  26. CALENDAR_ENABLED
  27. && ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
  28. switch (action.type) {
  29. case APP_WILL_MOUNT:
  30. // For legacy purposes, we've allowed the deserialization of
  31. // knownDomains. At this point, it should have already been
  32. // translated into the new state format (namely, base/known-domains)
  33. // and the app no longer needs it.
  34. if (typeof state.knownDomains !== 'undefined') {
  35. return set(state, 'knownDomains', undefined);
  36. }
  37. break;
  38. case SET_CALENDAR_AUTHORIZATION:
  39. return set(state, 'authorization', action.authorization);
  40. case SET_CALENDAR_EVENTS:
  41. return set(state, 'events', action.events);
  42. }
  43. return state;
  44. });