Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

reducer.js 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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.meet.jit.si',
  18. 'meet.jit.si'
  19. ];
  20. const STORE_NAME = 'features/base/known-domains';
  21. PersistenceRegistry.register(STORE_NAME);
  22. ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
  23. switch (action.type) {
  24. case ADD_KNOWN_DOMAINS:
  25. return _addKnownDomains(state, action.knownDomains);
  26. case APP_WILL_MOUNT:
  27. // In case persistence has deserialized a weird redux state:
  28. return _addKnownDomains(state, DEFAULT_STATE);
  29. default:
  30. return state;
  31. }
  32. });
  33. /**
  34. * Adds an array of known domains to the list of domains known to the feature
  35. * base/known-domains.
  36. *
  37. * @param {Object} state - The redux state.
  38. * @param {Array<string>} knownDomains - The array of known domains to add to
  39. * the list of domains known to the feature base/known-domains.
  40. * @private
  41. * @returns {Object} The next redux state.
  42. */
  43. function _addKnownDomains(state, knownDomains) {
  44. // In case persistence has deserialized a weird redux state:
  45. let nextState = Array.isArray(state) ? state : [];
  46. if (Array.isArray(knownDomains)) {
  47. nextState = Array.from(state);
  48. for (let knownDomain of knownDomains) {
  49. knownDomain = knownDomain.toLowerCase();
  50. !nextState.includes(knownDomain) && nextState.push(knownDomain);
  51. }
  52. }
  53. return nextState;
  54. }