bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/chat/message-form/container.jsx

42 lines
1.3 KiB
React
Raw Normal View History

2021-05-18 04:25:07 +08:00
import React, { useContext } from 'react';
import _ from 'lodash';
import { makeCall } from '/imports/ui/services/api';
2021-05-18 04:25:07 +08:00
import MessageForm from './component';
import ChatService from '/imports/ui/components/chat/service';
2021-08-05 19:03:24 +08:00
import LayoutContext from '../../layout/context';
const CHAT_CONFIG = Meteor.settings.public.chat;
const START_TYPING_THROTTLE_INTERVAL = 2000;
2021-05-18 04:25:07 +08:00
const MessageFormContainer = (props) => {
2021-08-05 19:03:24 +08:00
const layoutContext = useContext(LayoutContext);
const { layoutContextState } = layoutContext;
const { idChatOpen } = layoutContextState;
2021-05-18 04:25:07 +08:00
const handleSendMessage = (message) => {
ChatService.setUserSentMessage(true);
2021-05-18 04:25:07 +08:00
return ChatService.sendGroupMessage(message, idChatOpen);
};
2021-05-18 04:25:07 +08:00
const startUserTyping = _.throttle(
2021-08-09 22:24:02 +08:00
(chatId) => makeCall('startUserTyping', chatId),
2021-05-18 04:25:07 +08:00
START_TYPING_THROTTLE_INTERVAL,
);
const stopUserTyping = () => makeCall('stopUserTyping');
2021-05-18 04:25:07 +08:00
return (
<MessageForm
{...{
startUserTyping,
stopUserTyping,
UnsentMessagesCollection: ChatService.UnsentMessagesCollection,
minMessageLength: CHAT_CONFIG.min_message_length,
maxMessageLength: CHAT_CONFIG.max_message_length,
handleSendMessage,
idChatOpen,
...props,
}}
/>
);
};
export default MessageFormContainer;