您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

middleware.js 891B

1234567891011121314151617181920212223242526272829303132
  1. // @flow
  2. import { MiddlewareRegistry } from '../base/redux';
  3. import { playSound } from '../base/sounds';
  4. import { INCOMING_MSG_SOUND_ID } from '../chat/constants';
  5. import { RECEIVE_POLL } from './actionTypes';
  6. MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
  7. const result = next(action);
  8. switch (action.type) {
  9. // Middleware triggered when a poll is received
  10. case RECEIVE_POLL: {
  11. const state = getState();
  12. const isChatOpen: boolean = state['features/chat'].isOpen;
  13. const isPollsTabFocused: boolean = state['features/chat'].isPollsTabFocused;
  14. // Finally, we notify user they received a new poll if their pane is not opened
  15. if (action.notify && (!isChatOpen || !isPollsTabFocused)) {
  16. dispatch(playSound(INCOMING_MSG_SOUND_ID));
  17. }
  18. break;
  19. }
  20. }
  21. return result;
  22. });