Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

PrivateMessageMenuButton.tsx 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import React, { Component } from 'react';
  2. import { WithTranslation } from 'react-i18next';
  3. import { connect } from 'react-redux';
  4. import { IReduxState, IStore } from '../../../app/types';
  5. import { CHAT_ENABLED } from '../../../base/flags/constants';
  6. import { getFeatureFlag } from '../../../base/flags/functions';
  7. import { translate } from '../../../base/i18n/functions';
  8. import { IconMessage } from '../../../base/icons/svg';
  9. import { getParticipantById } from '../../../base/participants/functions';
  10. import { IParticipant } from '../../../base/participants/types';
  11. import ContextMenuItem from '../../../base/ui/components/web/ContextMenuItem';
  12. import { openChat } from '../../../chat/actions.web';
  13. import { NOTIFY_CLICK_MODE } from '../../../toolbox/constants';
  14. import { isButtonEnabled } from '../../../toolbox/functions.web';
  15. import { IButtonProps } from '../../types';
  16. interface IProps extends IButtonProps, WithTranslation {
  17. /**
  18. * True if the private chat functionality is disabled, hence the button is not visible.
  19. */
  20. _hidden: boolean;
  21. /**
  22. * The participant to send the message to.
  23. */
  24. _participant?: IParticipant;
  25. /**
  26. * Redux dispatch function.
  27. */
  28. dispatch: IStore['dispatch'];
  29. }
  30. /**
  31. * A custom implementation of the PrivateMessageButton specialized for
  32. * the web version of the remote video menu. When the web platform starts to use
  33. * the {@code AbstractButton} component for the remote video menu, we can get rid
  34. * of this component and use the generic button in the chat feature.
  35. */
  36. class PrivateMessageMenuButton extends Component<IProps> {
  37. /**
  38. * Instantiates a new Component instance.
  39. *
  40. * @inheritdoc
  41. */
  42. constructor(props: IProps) {
  43. super(props);
  44. this._onClick = this._onClick.bind(this);
  45. }
  46. /**
  47. * Implements React's {@link Component#render()}.
  48. *
  49. * @inheritdoc
  50. * @returns {ReactElement}
  51. */
  52. render() {
  53. const { _hidden, t } = this.props;
  54. if (_hidden) {
  55. return null;
  56. }
  57. return (
  58. <ContextMenuItem
  59. accessibilityLabel = { t('toolbar.accessibilityLabel.privateMessage') }
  60. icon = { IconMessage }
  61. onClick = { this._onClick }
  62. text = { t('toolbar.privateMessage') } />
  63. );
  64. }
  65. /**
  66. * Callback to be invoked on pressing the button.
  67. *
  68. * @param {React.MouseEvent|undefined} e - The click event.
  69. * @returns {void}
  70. */
  71. _onClick() {
  72. const { _participant, dispatch, notifyClick, notifyMode } = this.props;
  73. notifyClick?.();
  74. if (notifyMode === NOTIFY_CLICK_MODE.PREVENT_AND_NOTIFY) {
  75. return;
  76. }
  77. dispatch(openChat(_participant));
  78. }
  79. }
  80. /**
  81. * Maps part of the Redux store to the props of this component.
  82. *
  83. * @param {Object} state - The Redux state.
  84. * @param {IProps} ownProps - The own props of the component.
  85. * @returns {IProps}
  86. */
  87. function _mapStateToProps(state: IReduxState, ownProps: any) {
  88. const enabled = getFeatureFlag(state, CHAT_ENABLED, true);
  89. const { visible = enabled } = ownProps;
  90. return {
  91. _participant: getParticipantById(state, ownProps.participantID),
  92. visible,
  93. _hidden: typeof interfaceConfig !== 'undefined'
  94. && (interfaceConfig.DISABLE_PRIVATE_MESSAGES || !isButtonEnabled('chat', state))
  95. };
  96. }
  97. export default translate(connect(_mapStateToProps)(PrivateMessageMenuButton));