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

ChatButton.js 2.4KB

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