Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

PrivateMessageButton.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // @flow
  2. import { CHAT_ENABLED, getFeatureFlag } from '../../../base/flags';
  3. import { translate } from '../../../base/i18n';
  4. import { IconMessage, IconReply } from '../../../base/icons';
  5. import { getParticipantById } from '../../../base/participants';
  6. import { connect } from '../../../base/redux';
  7. import { AbstractButton, type AbstractButtonProps } from '../../../base/toolbox/components';
  8. import { handleLobbyChatInitialized, openChat } from '../../actions';
  9. export type Props = AbstractButtonProps & {
  10. /**
  11. * True if the message is a lobby chat message.
  12. */
  13. isLobbyMessage: boolean,
  14. /**
  15. * The ID of the participant that the message is to be sent.
  16. */
  17. participantID: string,
  18. /**
  19. * True if the button is rendered as a reply button.
  20. */
  21. reply: boolean,
  22. /**
  23. * Function to be used to translate i18n labels.
  24. */
  25. t: Function,
  26. /**
  27. * The Redux dispatch function.
  28. */
  29. dispatch: Function,
  30. /**
  31. * The participant object retrieved from Redux.
  32. */
  33. _participant: Object,
  34. };
  35. /**
  36. * Class to render a button that initiates the sending of a private message through chet.
  37. */
  38. class PrivateMessageButton extends AbstractButton<Props, any> {
  39. accessibilityLabel = 'toolbar.accessibilityLabel.privateMessage';
  40. icon = IconMessage;
  41. label = 'toolbar.privateMessage';
  42. toggledIcon = IconReply;
  43. /**
  44. * Handles clicking / pressing the button, and kicks the participant.
  45. *
  46. * @private
  47. * @returns {void}
  48. */
  49. _handleClick() {
  50. const { _participant, participantID, dispatch, isLobbyMessage } = this.props;
  51. if (isLobbyMessage) {
  52. dispatch(handleLobbyChatInitialized(participantID));
  53. } else {
  54. dispatch(openChat(_participant));
  55. }
  56. }
  57. /**
  58. * Helper function to be implemented by subclasses, which must return a
  59. * {@code boolean} value indicating if this button is toggled or not.
  60. *
  61. * @protected
  62. * @returns {boolean}
  63. */
  64. _isToggled() {
  65. return this.props.reply;
  66. }
  67. }
  68. /**
  69. * Maps part of the Redux store to the props of this component.
  70. *
  71. * @param {Object} state - The Redux state.
  72. * @param {Props} ownProps - The own props of the component.
  73. * @returns {Props}
  74. */
  75. export function _mapStateToProps(state: Object, ownProps: Props): $Shape<Props> {
  76. const enabled = getFeatureFlag(state, CHAT_ENABLED, true);
  77. const { visible = enabled } = ownProps;
  78. return {
  79. _participant: getParticipantById(state, ownProps.participantID),
  80. visible
  81. };
  82. }
  83. export default translate(connect(_mapStateToProps)(PrivateMessageButton));