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 3.3KB

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