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.

middleware.js 2.1KB

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