Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

AbstractChat.js 2.4KB

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