Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // @flow
  2. import { ENDPOINT_REACTION_NAME } from '../../../modules/API/constants';
  3. import { MiddlewareRegistry } from '../base/redux';
  4. import { isVpaasMeeting } from '../billing-counter/functions';
  5. import {
  6. SET_REACTIONS_MESSAGE,
  7. CLEAR_REACTIONS_MESSAGE,
  8. SEND_REACTION,
  9. PUSH_REACTION
  10. } from './actionTypes';
  11. import {
  12. addReactionsMessage,
  13. addReactionsMessageToChat,
  14. flushReactionsToChat,
  15. pushReaction,
  16. setReactionQueue
  17. } from './actions.any';
  18. import { REACTIONS } from './constants';
  19. import { messageToKeyArray, sendReactionsWebhook } from './functions.any';
  20. declare var APP: Object;
  21. /**
  22. * Middleware which intercepts Reactions actions to handle changes to the
  23. * visibility timeout of the Reactions.
  24. *
  25. * @param {Store} store - The redux store.
  26. * @returns {Function}
  27. */
  28. MiddlewareRegistry.register(store => next => action => {
  29. const { dispatch, getState } = store;
  30. switch (action.type) {
  31. case SET_REACTIONS_MESSAGE: {
  32. const { timeoutID, message } = getState()['features/reactions'];
  33. const { reaction } = action;
  34. clearTimeout(timeoutID);
  35. action.message = `${message}${reaction}`;
  36. action.timeoutID = setTimeout(() => {
  37. dispatch(flushReactionsToChat());
  38. }, 500);
  39. break;
  40. }
  41. case CLEAR_REACTIONS_MESSAGE: {
  42. const state = getState();
  43. const { message } = state['features/reactions'];
  44. if (isVpaasMeeting(state)) {
  45. sendReactionsWebhook(state, messageToKeyArray(message));
  46. }
  47. dispatch(addReactionsMessageToChat(message));
  48. break;
  49. }
  50. case SEND_REACTION: {
  51. const state = store.getState();
  52. const { conference } = state['features/base/conference'];
  53. if (conference) {
  54. conference.sendEndpointMessage('', {
  55. name: ENDPOINT_REACTION_NAME,
  56. reaction: action.reaction,
  57. timestamp: Date.now()
  58. });
  59. dispatch(addReactionsMessage(REACTIONS[action.reaction].message));
  60. dispatch(pushReaction(action.reaction));
  61. }
  62. break;
  63. }
  64. case PUSH_REACTION: {
  65. const queue = store.getState()['features/reactions'].queue;
  66. const reaction = action.reaction;
  67. dispatch(setReactionQueue([ ...queue, {
  68. reaction,
  69. uid: window.Date.now()
  70. } ]));
  71. }
  72. }
  73. return next(action);
  74. });