Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

reducer.ts 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import ReducerRegistry from '../base/redux/ReducerRegistry';
  2. import {
  3. ADD_REACTION_BUFFER,
  4. FLUSH_REACTION_BUFFER,
  5. SET_REACTION_QUEUE,
  6. SHOW_SOUNDS_NOTIFICATION,
  7. TOGGLE_REACTIONS_VISIBLE
  8. } from './actionTypes';
  9. import { IReactionEmojiProps } from './constants';
  10. export interface IReactionsState {
  11. /**
  12. * An array that contains the reactions buffer to be sent.
  13. */
  14. buffer: Array<string>;
  15. /**
  16. * Whether or not the disable reaction sounds notification was shown.
  17. */
  18. notificationDisplayed: boolean;
  19. /**
  20. * The array of reactions to animate.
  21. */
  22. queue: Array<IReactionEmojiProps>;
  23. /**
  24. * A number, non-zero value which identifies the timer created by a call
  25. * to setTimeout().
  26. */
  27. timeoutID: number | null;
  28. /**
  29. * The indicator that determines whether the reactions menu is visible.
  30. */
  31. visible: boolean;
  32. }
  33. export interface IReactionsAction extends Partial<IReactionsState> {
  34. /**
  35. * The message to be added to the chat.
  36. */
  37. message?: string;
  38. /**
  39. * The reaction to be added to buffer.
  40. */
  41. reaction?: string;
  42. /**
  43. * The reactions to be added to the animation queue.
  44. */
  45. reactions?: Array<string>;
  46. /**
  47. * The action type.
  48. */
  49. type: string;
  50. }
  51. /**
  52. * Returns initial state for reactions' part of Redux store.
  53. *
  54. * @private
  55. * @returns {IReactionsState}
  56. */
  57. function _getInitialState(): IReactionsState {
  58. return {
  59. visible: false,
  60. buffer: [],
  61. timeoutID: null,
  62. queue: [],
  63. notificationDisplayed: false
  64. };
  65. }
  66. ReducerRegistry.register<IReactionsState>(
  67. 'features/reactions',
  68. (state = _getInitialState(), action: IReactionsAction): IReactionsState => {
  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 ?? null
  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. });