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

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