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