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

PrivateMessageMenuButton.tsx 3.2KB

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