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.1KB

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