Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

PrivateMessageMenuButton.js 2.8KB

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