You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PrivateMessageButton.js 2.3KB

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