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.tsx 3.4KB

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