您最多选择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 { arePollsDisabled } from '../../../conference/functions.any';
  9. import { navigate } from '../../../mobile/navigation/components/conference/ConferenceNavigationContainerRef';
  10. import { screen } from '../../../mobile/navigation/routes';
  11. import { getUnreadPollCount } from '../../../polls/functions';
  12. import { getUnreadCount } from '../../functions';
  13. interface IProps extends AbstractButtonProps {
  14. /**
  15. * True if the polls feature is disabled.
  16. */
  17. _isPollsDisabled?: boolean;
  18. /**
  19. * The unread message count.
  20. */
  21. _unreadMessageCount: number;
  22. }
  23. /**
  24. * Implements an {@link AbstractButton} to open the chat screen on mobile.
  25. */
  26. class ChatButton extends AbstractButton<IProps> {
  27. accessibilityLabel = 'toolbar.accessibilityLabel.chat';
  28. icon = IconMessage;
  29. label = 'toolbar.chat';
  30. toggledIcon = IconChatUnread;
  31. /**
  32. * Handles clicking / pressing the button, and opens the appropriate dialog.
  33. *
  34. * @private
  35. * @returns {void}
  36. */
  37. _handleClick() {
  38. this.props._isPollsDisabled
  39. ? navigate(screen.conference.chat)
  40. : navigate(screen.conference.chatandpolls.main);
  41. }
  42. /**
  43. * Renders the button toggled when there are unread messages.
  44. *
  45. * @protected
  46. * @returns {boolean}
  47. */
  48. _isToggled() {
  49. return Boolean(this.props._unreadMessageCount);
  50. }
  51. }
  52. /**
  53. * Maps part of the redux state to the component's props.
  54. *
  55. * @param {Object} state - The Redux state.
  56. * @param {Object} ownProps - The properties explicitly passed to the component instance.
  57. * @returns {IProps}
  58. */
  59. function _mapStateToProps(state: IReduxState, ownProps: any) {
  60. const enabled = getFeatureFlag(state, CHAT_ENABLED, true);
  61. const { visible = enabled } = ownProps;
  62. return {
  63. _isPollsDisabled: arePollsDisabled(state),
  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));