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.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // @flow
  2. import { assign, ReducerRegistry } from '../base/redux';
  3. import {
  4. CANCEL_LOGIN,
  5. STOP_WAIT_FOR_OWNER,
  6. UPGRADE_ROLE_FINISHED,
  7. UPGRADE_ROLE_STARTED,
  8. WAIT_FOR_OWNER
  9. } from './actionTypes';
  10. /**
  11. * Listens for actions which change the state of the authentication feature.
  12. *
  13. * @param {Object} state - The Redux state of the authentication feature.
  14. * @param {Object} action - Action object.
  15. * @param {string} action.type - Type of action.
  16. * @returns {Object}
  17. */
  18. ReducerRegistry.register('features/authentication', (state = {}, action) => {
  19. switch (action.type) {
  20. case CANCEL_LOGIN:
  21. return assign(state, {
  22. error: undefined,
  23. progress: undefined,
  24. thenableWithCancel: undefined
  25. });
  26. case STOP_WAIT_FOR_OWNER:
  27. return assign(state, {
  28. error: undefined,
  29. waitForOwnerTimeoutID: undefined
  30. });
  31. case UPGRADE_ROLE_FINISHED: {
  32. let { thenableWithCancel } = action;
  33. if (state.thenableWithCancel === thenableWithCancel) {
  34. const { error, progress } = action;
  35. // An error interrupts the process of authenticating and upgrading
  36. // the role of the local participant/user i.e. the process is no
  37. // more. Obviously, the process seizes to exist also when it does
  38. // its whole job.
  39. if (error || progress === 1) {
  40. thenableWithCancel = undefined;
  41. }
  42. return assign(state, {
  43. error,
  44. progress: progress || undefined,
  45. thenableWithCancel
  46. });
  47. }
  48. break;
  49. }
  50. case UPGRADE_ROLE_STARTED:
  51. return assign(state, {
  52. error: undefined,
  53. progress: undefined,
  54. thenableWithCancel: action.thenableWithCancel
  55. });
  56. case WAIT_FOR_OWNER:
  57. return assign(state, {
  58. waitForOwnerTimeoutID: action.waitForOwnerTimeoutID
  59. });
  60. }
  61. return state;
  62. });