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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 { openChat } from '../../../chat/';
  7. import {
  8. _mapStateToProps as _abstractMapStateToProps,
  9. type Props as AbstractProps
  10. } from '../../../chat/components/PrivateMessageButton';
  11. import { isButtonEnabled } from '../../../toolbox/functions.web';
  12. import VideoMenuButton from './VideoMenuButton';
  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 { participantID, t, _hidden } = this.props;
  44. if (_hidden) {
  45. return null;
  46. }
  47. return (
  48. <VideoMenuButton
  49. buttonText = { t('toolbar.privateMessage') }
  50. icon = { IconMessage }
  51. id = { `privmsglink_${participantID}` }
  52. onClick = { this._onClick } />
  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));