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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // @flow
  2. import { AbstractButton, type AbstractButtonProps } from '../../base/toolbox';
  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 { setPrivateMessageRecipient } 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 participant object retreived from Redux.
  23. */
  24. _participant: Object,
  25. /**
  26. * Function to dispatch the result of the participant selection to send a private message.
  27. */
  28. _setPrivateMessageRecipient: Function
  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 { _participant, _setPrivateMessageRecipient } = this.props;
  46. _setPrivateMessageRecipient(_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 props of this component to Redux actions.
  61. *
  62. * @param {Function} dispatch - The Redux dispatch function.
  63. * @returns {Props}
  64. */
  65. export function _mapDispatchToProps(dispatch: Function): $Shape<Props> {
  66. return {
  67. _setPrivateMessageRecipient: participant => {
  68. dispatch(setPrivateMessageRecipient(participant));
  69. }
  70. };
  71. }
  72. /**
  73. * Maps part of the Redux store to the props of this component.
  74. *
  75. * @param {Object} state - The Redux state.
  76. * @param {Props} ownProps - The own props of the component.
  77. * @returns {Props}
  78. */
  79. export function _mapStateToProps(state: Object, ownProps: Props): $Shape<Props> {
  80. return {
  81. _participant: getParticipantById(state, ownProps.participantID)
  82. };
  83. }
  84. export default translate(connect(_mapStateToProps, _mapDispatchToProps)(PrivateMessageButton));