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.

reducer.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // @flow
  2. import { APP_WILL_MOUNT } from '../../app';
  3. import { ReducerRegistry } from '../redux';
  4. import { PersistenceRegistry } from '../storage';
  5. import { ADD_KNOWN_DOMAINS } from './actionTypes';
  6. /**
  7. * The default list of domains known to the feature base/known-domains.
  8. * Generally, it should be in sync with the domains associated with the app
  9. * through its manifest (in other words, Universal Links, deep linking). Anyway,
  10. * we need a hardcoded list because it has proven impossible to programmatically
  11. * read the information out of the app's manifests: App Store strips the
  12. * associated domains manifest out of the app so it's never downloaded on the
  13. * client and we did not spend a lot of effort to read the associated domains
  14. * out of the Andorid manifest.
  15. */
  16. export const DEFAULT_STATE = [
  17. 'beta.hipchat.me',
  18. 'beta.meet.jit.si',
  19. 'chaos.hipchat.me',
  20. 'enso.me',
  21. 'hipchat.me',
  22. 'meet.jit.si'
  23. ];
  24. const STORE_NAME = 'features/base/known-domains';
  25. PersistenceRegistry.register(STORE_NAME);
  26. ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
  27. switch (action.type) {
  28. case ADD_KNOWN_DOMAINS:
  29. return _addKnownDomains(state, action.knownDomains);
  30. case APP_WILL_MOUNT:
  31. // In case persistence has deserialized a weird redux state:
  32. return _addKnownDomains(state, DEFAULT_STATE);
  33. default:
  34. return state;
  35. }
  36. });
  37. /**
  38. * Adds an array of known domains to the list of domains known to the feature
  39. * base/known-domains.
  40. *
  41. * @param {Object} state - The redux state.
  42. * @param {Array<string>} knownDomains - The array of known domains to add to
  43. * the list of domains known to the feature base/known-domains.
  44. * @private
  45. * @returns {Object} The next redux state.
  46. */
  47. function _addKnownDomains(state, knownDomains) {
  48. // In case persistence has deserialized a weird redux state:
  49. let nextState = Array.isArray(state) ? state : [];
  50. if (Array.isArray(knownDomains)) {
  51. nextState = Array.from(state);
  52. for (let knownDomain of knownDomains) {
  53. knownDomain = knownDomain.toLowerCase();
  54. !nextState.includes(knownDomain) && nextState.push(knownDomain);
  55. }
  56. }
  57. return nextState;
  58. }