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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import { CHAT_ENABLED, getFeatureFlag } from '../../../base/flags';
  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 { handleLobbyChatInitialized, openChat } from '../../../chat/actions.native';
  8. import { navigate } from '../../../mobile/navigation/components/conference/ConferenceNavigationContainerRef';
  9. import { screen } from '../../../mobile/navigation/routes';
  10. export type Props = AbstractButtonProps & {
  11. /**
  12. * The Redux Dispatch function.
  13. */
  14. dispatch: Function,
  15. /**
  16. * The ID of the participant that the message is to be sent.
  17. */
  18. participantID: string,
  19. /**
  20. * True if the button is rendered as a reply button.
  21. */
  22. reply: boolean,
  23. /**
  24. * Function to be used to translate i18n labels.
  25. */
  26. t: Function,
  27. /**
  28. * True if the polls feature is disabled.
  29. */
  30. _isPollsDisabled: boolean,
  31. /**
  32. * True if message is a lobby chat message.
  33. */
  34. _isLobbyMessage: boolean,
  35. /**
  36. * The participant object retrieved from Redux.
  37. */
  38. _participant: Object,
  39. };
  40. /**
  41. * Class to render a button that initiates the sending of a private message through chet.
  42. */
  43. class PrivateMessageButton extends AbstractButton<Props, any> {
  44. accessibilityLabel = 'toolbar.accessibilityLabel.privateMessage';
  45. icon = IconMessage;
  46. label = 'toolbar.privateMessage';
  47. toggledIcon = IconReply;
  48. /**
  49. * Handles clicking / pressing the button.
  50. *
  51. * @private
  52. * @returns {void}
  53. */
  54. _handleClick() {
  55. if (this.props._isLobbyMessage) {
  56. this.props.dispatch(handleLobbyChatInitialized(this.props.participantID));
  57. }
  58. this.props.dispatch(openChat(this.props._participant));
  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) {
  89. const enabled = getFeatureFlag(state, CHAT_ENABLED, true);
  90. const { disablePolls } = state['features/base/config'];
  91. const { visible = enabled, isLobbyMessage, participantID } = ownProps;
  92. return {
  93. _isPollsDisabled: disablePolls,
  94. _participant: getParticipantById(state, participantID),
  95. _isLobbyMessage: isLobbyMessage,
  96. visible
  97. };
  98. }
  99. export default translate(connect(_mapStateToProps)(PrivateMessageButton));