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.

ChatButton.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // @flow
  2. import { getLocalParticipant } from '../../../base/participants';
  3. import { connect } from '../../../base/redux';
  4. import {
  5. AbstractButton,
  6. type AbstractButtonProps
  7. } from '../../../base/toolbox';
  8. import { openDisplayNamePrompt } from '../../../display-name';
  9. import { toggleChat } from '../../actions';
  10. import { getUnreadCount } from '../../functions';
  11. type Props = AbstractButtonProps & {
  12. /**
  13. * Function to display chat.
  14. *
  15. * @protected
  16. */
  17. _displayChat: Function,
  18. /**
  19. * Function to diaply the name prompt before displaying the chat
  20. * window, if the user has no display name set.
  21. */
  22. _displayNameInputDialog: Function,
  23. /**
  24. * Whether or not to block chat access with a nickname input form.
  25. */
  26. _showNamePrompt: boolean,
  27. /**
  28. * The unread message count.
  29. */
  30. _unreadMessageCount: number
  31. };
  32. /**
  33. * Implements an {@link AbstractButton} to open the chat screen on mobile.
  34. */
  35. class ChatButton extends AbstractButton<Props, *> {
  36. accessibilityLabel = 'toolbar.accessibilityLabel.chat';
  37. iconName = 'chat';
  38. label = 'toolbar.chat';
  39. toggledIconName = 'chat-unread';
  40. /**
  41. * Handles clicking / pressing the button, and opens the appropriate dialog.
  42. *
  43. * @private
  44. * @returns {void}
  45. */
  46. _handleClick() {
  47. if (this.props._showNamePrompt) {
  48. this.props._displayNameInputDialog(() => {
  49. this.props._displayChat();
  50. });
  51. } else {
  52. this.props._displayChat();
  53. }
  54. }
  55. /**
  56. * Renders the button toggled when there are unread messages.
  57. *
  58. * @protected
  59. * @returns {boolean}
  60. */
  61. _isToggled() {
  62. return Boolean(this.props._unreadMessageCount);
  63. }
  64. }
  65. /**
  66. * Maps redux actions to the props of the component.
  67. *
  68. * @param {Function} dispatch - The redux action {@code dispatch} function.
  69. * @returns {{
  70. * _displayChat,
  71. * _displayNameInputDialog
  72. * }}
  73. * @private
  74. */
  75. function _mapDispatchToProps(dispatch: Function) {
  76. return {
  77. /**
  78. * Launches native invite dialog.
  79. *
  80. * @private
  81. * @returns {void}
  82. */
  83. _displayChat() {
  84. dispatch(toggleChat());
  85. },
  86. /**
  87. * Displays a display name prompt.
  88. *
  89. * @param {Function} onPostSubmit - The function to invoke after a
  90. * succesfulsetting of the display name.
  91. * @returns {void}
  92. */
  93. _displayNameInputDialog(onPostSubmit) {
  94. dispatch(openDisplayNamePrompt(onPostSubmit));
  95. }
  96. };
  97. }
  98. /**
  99. * Maps part of the redux state to the component's props.
  100. *
  101. * @param {Object} state - The Redux state.
  102. * @returns {{
  103. * _unreadMessageCount
  104. * }}
  105. */
  106. function _mapStateToProps(state) {
  107. const localParticipant = getLocalParticipant(state);
  108. return {
  109. _showNamePrompt: !localParticipant.name,
  110. _unreadMessageCount: getUnreadCount(state)
  111. };
  112. }
  113. export default connect(_mapStateToProps, _mapDispatchToProps)(ChatButton);