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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { MiddlewareRegistry } from '../base/redux';
  2. import { ADD_GIF_FOR_PARTICIPANT, HIDE_GIF_FOR_PARTICIPANT, SHOW_GIF_FOR_PARTICIPANT } from './actionTypes';
  3. import { removeGif } from './actions';
  4. import { GIF_DEFAULT_TIMEOUT } from './constants';
  5. import { getGifForParticipant } from './functions';
  6. /**
  7. * Middleware which intercepts Gifs actions to handle changes to the
  8. * visibility timeout of the Gifs.
  9. *
  10. * @param {Store} store - The redux store.
  11. * @returns {Function}
  12. */
  13. MiddlewareRegistry.register(store => next => action => {
  14. const { dispatch, getState } = store;
  15. const state = getState();
  16. switch (action.type) {
  17. case ADD_GIF_FOR_PARTICIPANT: {
  18. const id = action.participantId;
  19. const { giphy } = state['features/base/config'];
  20. _clearGifTimeout(state, id);
  21. const timeoutID = setTimeout(() => dispatch(removeGif(id)), giphy?.tileTime || GIF_DEFAULT_TIMEOUT);
  22. action.timeoutID = timeoutID;
  23. break;
  24. }
  25. case SHOW_GIF_FOR_PARTICIPANT: {
  26. const id = action.participantId;
  27. _clearGifTimeout(state, id);
  28. break;
  29. }
  30. case HIDE_GIF_FOR_PARTICIPANT: {
  31. const { giphy } = state['features/base/config'];
  32. const id = action.participantId;
  33. const timeoutID = setTimeout(() => dispatch(removeGif(id)), giphy?.tileTime || GIF_DEFAULT_TIMEOUT);
  34. action.timeoutID = timeoutID;
  35. break;
  36. }
  37. }
  38. return next(action);
  39. });
  40. /**
  41. * Clears GIF timeout.
  42. *
  43. * @param {Object} state - Redux state.
  44. * @param {string} id - Id of the participant for whom to clear the timeout.
  45. * @returns {void}
  46. */
  47. function _clearGifTimeout(state, id) {
  48. const gif = getGifForParticipant(state, id);
  49. clearTimeout(gif?.timeoutID);
  50. }