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.

PrivateMessageMenuButton.js 2.6KB

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