Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

reducer.ts 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import PersistenceRegistry from '../base/redux/PersistenceRegistry';
  2. import ReducerRegistry from '../base/redux/ReducerRegistry';
  3. import { assign } from '../base/redux/functions';
  4. import {
  5. CANCEL_LOGIN,
  6. SET_TOKEN_AUTH_URL_SUCCESS,
  7. STOP_WAIT_FOR_OWNER,
  8. UPGRADE_ROLE_FINISHED,
  9. UPGRADE_ROLE_STARTED,
  10. WAIT_FOR_OWNER
  11. } from './actionTypes';
  12. export interface IAuthenticationState {
  13. error?: Object | undefined;
  14. progress?: number | undefined;
  15. thenableWithCancel?: {
  16. cancel: Function;
  17. };
  18. tokenAuthUrlSuccessful?: boolean;
  19. waitForOwnerTimeoutID?: number;
  20. }
  21. /**
  22. * Sets up the persistence of the feature {@code authentication}.
  23. */
  24. PersistenceRegistry.register('features/authentication', {
  25. tokenAuthUrlSuccessful: true
  26. });
  27. /**
  28. * Listens for actions which change the state of the authentication feature.
  29. *
  30. * @param {Object} state - The Redux state of the authentication feature.
  31. * @param {Object} action - Action object.
  32. * @param {string} action.type - Type of action.
  33. * @returns {Object}
  34. */
  35. ReducerRegistry.register<IAuthenticationState>('features/authentication',
  36. (state = {}, action): IAuthenticationState => {
  37. switch (action.type) {
  38. case CANCEL_LOGIN:
  39. return assign(state, {
  40. error: undefined,
  41. progress: undefined,
  42. thenableWithCancel: undefined
  43. });
  44. case SET_TOKEN_AUTH_URL_SUCCESS:
  45. return assign(state, {
  46. tokenAuthUrlSuccessful: action.value
  47. });
  48. case STOP_WAIT_FOR_OWNER:
  49. return assign(state, {
  50. error: undefined,
  51. waitForOwnerTimeoutID: undefined
  52. });
  53. case UPGRADE_ROLE_FINISHED: {
  54. let { thenableWithCancel } = action;
  55. if (state.thenableWithCancel === thenableWithCancel) {
  56. const { error, progress } = action;
  57. // An error interrupts the process of authenticating and upgrading
  58. // the role of the local participant/user i.e. the process is no
  59. // more. Obviously, the process seizes to exist also when it does
  60. // its whole job.
  61. if (error || progress === 1) {
  62. thenableWithCancel = undefined;
  63. }
  64. return assign(state, {
  65. error,
  66. progress: progress || undefined,
  67. thenableWithCancel
  68. });
  69. }
  70. break;
  71. }
  72. case UPGRADE_ROLE_STARTED:
  73. return assign(state, {
  74. error: undefined,
  75. progress: undefined,
  76. thenableWithCancel: action.thenableWithCancel
  77. });
  78. case WAIT_FOR_OWNER:
  79. return assign(state, {
  80. waitForOwnerTimeoutID: action.waitForOwnerTimeoutID
  81. });
  82. }
  83. return state;
  84. });