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.1KB

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