// @flow import { Component } from 'react'; import type { Dispatch } from 'redux'; import { isMobileBrowser } from '../../base/environment/utils'; import { getLocalParticipant } from '../../base/participants'; import { sendMessage, toggleChat } from '../actions'; import { DESKTOP_SMALL_WIDTH_THRESHOLD, MOBILE_SMALL_WIDTH_THRESHOLD } from '../constants'; /** * The type of the React {@code Component} props of {@code AbstractChat}. */ export type Props = { /** * Whether the chat is opened in a modal or not (computed based on window width). */ _isModal: boolean, /** * True if the chat window should be rendered. */ _isOpen: boolean, /** * All the chat messages in the conference. */ _messages: Array, /** * Function to send a text message. * * @protected */ _onSendMessage: Function, /** * Function to toggle the chat window. */ _onToggleChat: Function, /** * Whether or not to block chat access with a nickname input form. */ _showNamePrompt: boolean, /** * The Redux dispatch function. */ dispatch: Dispatch, /** * Function to be used to translate i18n labels. */ t: Function }; /** * Implements an abstract chat panel. */ export default class AbstractChat extends Component

{} /** * Maps redux actions to the props of the component. * * @param {Function} dispatch - The redux action {@code dispatch} function. * @returns {{ * _onSendMessage: Function, * _onToggleChat: Function * }} * @private */ export function _mapDispatchToProps(dispatch: Dispatch) { return { /** * Toggles the chat window. * * @returns {Function} */ _onToggleChat() { dispatch(toggleChat()); }, /** * Sends a text message. * * @private * @param {string} text - The text message to be sent. * @returns {void} * @type {Function} */ _onSendMessage(text: string) { dispatch(sendMessage(text)); } }; } /** * Maps (parts of) the redux state to {@link Chat} React {@code Component} * props. * * @param {Object} state - The redux store/state. * @private * @returns {{ * _isOpen: boolean, * _messages: Array, * _showNamePrompt: boolean * }} */ export function _mapStateToProps(state: Object) { const { isOpen, messages } = state['features/chat']; const _localParticipant = getLocalParticipant(state); return { _isModal: isMobileBrowser() ? window.innerWidth <= MOBILE_SMALL_WIDTH_THRESHOLD : window.innerWidth <= DESKTOP_SMALL_WIDTH_THRESHOLD, _isOpen: isOpen, _messages: messages, _showNamePrompt: !_localParticipant.name }; }