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.

AbstractChat.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // @flow
  2. import { Component } from 'react';
  3. import type { Dispatch } from 'redux';
  4. import { getLocalParticipant } from '../../base/participants';
  5. import { sendMessage, toggleChat } from '../actions';
  6. /**
  7. * The type of the React {@code Component} props of {@code AbstractChat}.
  8. */
  9. export type Props = {
  10. /**
  11. * True if the chat window should be rendered.
  12. */
  13. _isOpen: boolean,
  14. /**
  15. * All the chat messages in the conference.
  16. */
  17. _messages: Array<Object>,
  18. /**
  19. * Function to send a text message.
  20. *
  21. * @protected
  22. */
  23. _onSendMessage: Function,
  24. /**
  25. * Function to toggle the chat window.
  26. */
  27. _onToggleChat: Function,
  28. /**
  29. * Whether or not to block chat access with a nickname input form.
  30. */
  31. _showNamePrompt: boolean,
  32. /**
  33. * The Redux dispatch function.
  34. */
  35. dispatch: Dispatch<any>,
  36. /**
  37. * Function to be used to translate i18n labels.
  38. */
  39. t: Function
  40. };
  41. /**
  42. * Implements an abstract chat panel.
  43. */
  44. export default class AbstractChat<P: Props> extends Component<P> {}
  45. /**
  46. * Maps redux actions to the props of the component.
  47. *
  48. * @param {Function} dispatch - The redux action {@code dispatch} function.
  49. * @returns {{
  50. * _onSendMessage: Function,
  51. * _onToggleChat: Function
  52. * }}
  53. * @private
  54. */
  55. export function _mapDispatchToProps(dispatch: Dispatch<any>) {
  56. return {
  57. /**
  58. * Toggles the chat window.
  59. *
  60. * @returns {Function}
  61. */
  62. _onToggleChat() {
  63. dispatch(toggleChat());
  64. },
  65. /**
  66. * Sends a text message.
  67. *
  68. * @private
  69. * @param {string} text - The text message to be sent.
  70. * @returns {void}
  71. * @type {Function}
  72. */
  73. _onSendMessage(text: string) {
  74. dispatch(sendMessage(text));
  75. }
  76. };
  77. }
  78. /**
  79. * Maps (parts of) the redux state to {@link Chat} React {@code Component}
  80. * props.
  81. *
  82. * @param {Object} state - The redux store/state.
  83. * @private
  84. * @returns {{
  85. * _isOpen: boolean,
  86. * _messages: Array<Object>,
  87. * _showNamePrompt: boolean
  88. * }}
  89. */
  90. export function _mapStateToProps(state: Object) {
  91. const { isOpen, messages } = state['features/chat'];
  92. const _localParticipant = getLocalParticipant(state);
  93. return {
  94. _isOpen: isOpen,
  95. _messages: messages,
  96. _showNamePrompt: !_localParticipant.name
  97. };
  98. }