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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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, openChat } from '../../../chat/actions';
  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.
  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.dispatch(openChat(this.props._participant));
  60. this.props._isPollsDisabled
  61. ? navigate(screen.conference.chat, {
  62. privateMessageRecipient: this.props._participant
  63. })
  64. : navigate(screen.conference.chatandpolls.main, {
  65. screen: screen.conference.chatandpolls.tab.chat,
  66. params: {
  67. privateMessageRecipient: this.props._participant
  68. }
  69. });
  70. }
  71. /**
  72. * Helper function to be implemented by subclasses, which must return a
  73. * {@code boolean} value indicating if this button is toggled or not.
  74. *
  75. * @protected
  76. * @returns {boolean}
  77. */
  78. _isToggled() {
  79. return this.props.reply;
  80. }
  81. }
  82. /**
  83. * Maps part of the Redux store to the props of this component.
  84. *
  85. * @param {Object} state - The Redux state.
  86. * @param {Props} ownProps - The own props of the component.
  87. * @returns {Props}
  88. */
  89. export function _mapStateToProps(state: Object, ownProps: Props): $Shape<Props> {
  90. const enabled = getFeatureFlag(state, CHAT_ENABLED, true);
  91. const { disablePolls } = state['features/base/config'];
  92. const { visible = enabled, isLobbyMessage, participantID } = ownProps;
  93. return {
  94. _isPollsDisabled: disablePolls,
  95. _participant: getParticipantById(state, participantID),
  96. _isLobbyMessage: isLobbyMessage,
  97. visible
  98. };
  99. }
  100. export default translate(connect(_mapStateToProps)(PrivateMessageButton));