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

ChatButton.ts 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { connect } from 'react-redux';
  2. import { IReduxState } from '../../../app/types';
  3. import { CHAT_ENABLED } from '../../../base/flags/constants';
  4. import { getFeatureFlag } from '../../../base/flags/functions';
  5. import { translate } from '../../../base/i18n/functions';
  6. import { IconChatUnread, IconMessage } from '../../../base/icons/svg';
  7. import AbstractButton, { IProps as AbstractButtonProps } from '../../../base/toolbox/components/AbstractButton';
  8. import { navigate } from '../../../mobile/navigation/components/conference/ConferenceNavigationContainerRef';
  9. import { screen } from '../../../mobile/navigation/routes';
  10. import { getUnreadPollCount } from '../../../polls/functions';
  11. import { getUnreadCount } from '../../functions';
  12. interface IProps extends AbstractButtonProps {
  13. /**
  14. * True if the polls feature is disabled.
  15. */
  16. _isPollsDisabled?: boolean;
  17. /**
  18. * The unread message count.
  19. */
  20. _unreadMessageCount: number;
  21. }
  22. /**
  23. * Implements an {@link AbstractButton} to open the chat screen on mobile.
  24. */
  25. class ChatButton extends AbstractButton<IProps> {
  26. accessibilityLabel = 'toolbar.accessibilityLabel.chat';
  27. icon = IconMessage;
  28. label = 'toolbar.chat';
  29. toggledIcon = IconChatUnread;
  30. /**
  31. * Handles clicking / pressing the button, and opens the appropriate dialog.
  32. *
  33. * @private
  34. * @returns {void}
  35. */
  36. _handleClick() {
  37. this.props._isPollsDisabled
  38. ? navigate(screen.conference.chat)
  39. : navigate(screen.conference.chatandpolls.main);
  40. }
  41. /**
  42. * Renders the button toggled when there are unread messages.
  43. *
  44. * @protected
  45. * @returns {boolean}
  46. */
  47. _isToggled() {
  48. return Boolean(this.props._unreadMessageCount);
  49. }
  50. }
  51. /**
  52. * Maps part of the redux state to the component's props.
  53. *
  54. * @param {Object} state - The Redux state.
  55. * @param {Object} ownProps - The properties explicitly passed to the component instance.
  56. * @returns {IProps}
  57. */
  58. function _mapStateToProps(state: IReduxState, ownProps: any) {
  59. const enabled = getFeatureFlag(state, CHAT_ENABLED, true);
  60. const { disablePolls } = state['features/base/config'];
  61. const { visible = enabled } = ownProps;
  62. return {
  63. _isPollsDisabled: disablePolls,
  64. // The toggled icon should also be available for new polls
  65. _unreadMessageCount: getUnreadCount(state) || getUnreadPollCount(state),
  66. visible
  67. };
  68. }
  69. export default translate(connect(_mapStateToProps)(ChatButton));