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.ts 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // @ts-ignore
  2. import { ReducerRegistry } from '../base/redux';
  3. import {
  4. TOGGLE_REACTIONS_VISIBLE,
  5. SET_REACTION_QUEUE,
  6. ADD_REACTION_BUFFER,
  7. FLUSH_REACTION_BUFFER,
  8. SHOW_SOUNDS_NOTIFICATION
  9. } from './actionTypes';
  10. import { ReactionEmojiProps } from './constants';
  11. interface State {
  12. /**
  13. * The indicator that determines whether the reactions menu is visible.
  14. */
  15. visible: boolean,
  16. /**
  17. * An array that contains the reactions buffer to be sent.
  18. */
  19. buffer: Array<string>,
  20. /**
  21. * A number, non-zero value which identifies the timer created by a call
  22. * to setTimeout().
  23. */
  24. timeoutID: number|null,
  25. /**
  26. * The array of reactions to animate.
  27. */
  28. queue: Array<ReactionEmojiProps>,
  29. /**
  30. * Whether or not the disable reaction sounds notification was shown.
  31. */
  32. notificationDisplayed: boolean
  33. }
  34. export interface ReactionsAction extends Partial<State> {
  35. /**
  36. * The message to be added to the chat.
  37. */
  38. message?: string,
  39. /**
  40. * The reaction to be added to buffer.
  41. */
  42. reaction?: string,
  43. /**
  44. * The reactions to be added to the animation queue.
  45. */
  46. reactions?: Array<string>,
  47. /**
  48. * The action type.
  49. */
  50. type: string
  51. }
  52. /**
  53. * Returns initial state for reactions' part of Redux store.
  54. *
  55. * @private
  56. */
  57. function _getInitialState(): State {
  58. return {
  59. visible: false,
  60. buffer: [],
  61. timeoutID: null,
  62. queue: [],
  63. notificationDisplayed: false
  64. };
  65. }
  66. ReducerRegistry.register(
  67. 'features/reactions',
  68. (state: State = _getInitialState(), action: ReactionsAction) => {
  69. switch (action.type) {
  70. case TOGGLE_REACTIONS_VISIBLE:
  71. return {
  72. ...state,
  73. visible: !state.visible
  74. };
  75. case ADD_REACTION_BUFFER:
  76. return {
  77. ...state,
  78. buffer: action.buffer,
  79. timeoutID: action.timeoutID
  80. };
  81. case FLUSH_REACTION_BUFFER:
  82. return {
  83. ...state,
  84. buffer: [],
  85. timeoutID: null
  86. };
  87. case SET_REACTION_QUEUE: {
  88. return {
  89. ...state,
  90. queue: action.queue
  91. };
  92. }
  93. case SHOW_SOUNDS_NOTIFICATION: {
  94. return {
  95. ...state,
  96. notificationDisplayed: true
  97. };
  98. }
  99. }
  100. return state;
  101. });