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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import { CONFERENCE_WILL_LEAVE } from '../base/conference/actionTypes';
  2. import ReducerRegistry from '../base/redux/ReducerRegistry';
  3. import {
  4. CLEAR_VISITOR_PROMOTION_REQUEST,
  5. I_AM_VISITOR_MODE,
  6. SET_IN_VISITORS_QUEUE,
  7. SET_VISITORS_SUPPORTED,
  8. SET_VISITOR_DEMOTE_ACTOR,
  9. UPDATE_VISITORS_COUNT,
  10. UPDATE_VISITORS_IN_QUEUE_COUNT,
  11. VISITOR_PROMOTION_REQUEST
  12. } from './actionTypes';
  13. import { IPromotionRequest } from './types';
  14. const DEFAULT_STATE = {
  15. count: 0,
  16. iAmVisitor: false,
  17. inQueue: false,
  18. inQueueCount: 0,
  19. showNotification: false,
  20. supported: false,
  21. promotionRequests: []
  22. };
  23. export interface IVisitorsState {
  24. count?: number;
  25. demoteActorDisplayName?: string;
  26. iAmVisitor: boolean;
  27. inQueue: boolean;
  28. inQueueCount?: number;
  29. promotionRequests: IPromotionRequest[];
  30. supported: boolean;
  31. }
  32. ReducerRegistry.register<IVisitorsState>('features/visitors', (state = DEFAULT_STATE, action): IVisitorsState => {
  33. switch (action.type) {
  34. case CONFERENCE_WILL_LEAVE: {
  35. return {
  36. ...state,
  37. ...DEFAULT_STATE,
  38. // If the action was called because a visitor was promoted don't clear the iAmVisitor field. It will be set
  39. // to false with the I_AM_VISITOR_MODE action and we will be able to distinguish leaving the conference use
  40. // case and promoting a visitor use case.
  41. iAmVisitor: action.isRedirect ? state.iAmVisitor : DEFAULT_STATE.iAmVisitor
  42. };
  43. }
  44. case UPDATE_VISITORS_COUNT: {
  45. if (state.count === action.count) {
  46. return state;
  47. }
  48. return {
  49. ...state,
  50. count: action.count
  51. };
  52. }
  53. case UPDATE_VISITORS_IN_QUEUE_COUNT: {
  54. if (state.count === action.count) {
  55. return state;
  56. }
  57. return {
  58. ...state,
  59. inQueueCount: action.count
  60. };
  61. }
  62. case I_AM_VISITOR_MODE: {
  63. return {
  64. ...state,
  65. iAmVisitor: action.enabled
  66. };
  67. }
  68. case SET_IN_VISITORS_QUEUE: {
  69. return {
  70. ...state,
  71. inQueue: action.value
  72. };
  73. }
  74. case SET_VISITOR_DEMOTE_ACTOR: {
  75. return {
  76. ...state,
  77. demoteActorDisplayName: action.displayName
  78. };
  79. }
  80. case SET_VISITORS_SUPPORTED: {
  81. return {
  82. ...state,
  83. supported: action.value
  84. };
  85. }
  86. case VISITOR_PROMOTION_REQUEST: {
  87. const currentRequests = state.promotionRequests || [];
  88. return {
  89. ...state,
  90. promotionRequests: [ ...currentRequests, action.request ]
  91. };
  92. }
  93. case CLEAR_VISITOR_PROMOTION_REQUEST: {
  94. let currentRequests = state.promotionRequests || [];
  95. currentRequests = currentRequests.filter(r => r.from !== action.request.from);
  96. return {
  97. ...state,
  98. promotionRequests: currentRequests
  99. };
  100. }
  101. }
  102. return state;
  103. });