2021-05-18 04:25:07 +08:00
|
|
|
import React, { useContext } from 'react';
|
2021-01-22 00:05:41 +08:00
|
|
|
import _ from 'lodash';
|
2019-08-22 05:56:32 +08:00
|
|
|
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';
|
|
|
|
import { NLayoutContext } from '../../layout/context/context';
|
2019-08-09 02:53:08 +08:00
|
|
|
|
|
|
|
const CHAT_CONFIG = Meteor.settings.public.chat;
|
2021-01-22 01:05:59 +08:00
|
|
|
const START_TYPING_THROTTLE_INTERVAL = 2000;
|
2019-08-22 05:56:32 +08:00
|
|
|
|
2021-05-18 04:25:07 +08:00
|
|
|
const MessageFormContainer = (props) => {
|
|
|
|
const newLayoutContext = useContext(NLayoutContext);
|
|
|
|
const { newLayoutContextState } = newLayoutContext;
|
|
|
|
const { idChatOpen } = newLayoutContextState;
|
|
|
|
const handleSendMessage = (message) => {
|
2021-01-20 01:06:32 +08:00
|
|
|
ChatService.setUserSentMessage(true);
|
2021-05-18 04:25:07 +08:00
|
|
|
return ChatService.sendGroupMessage(message, idChatOpen);
|
2019-08-09 02:53:08 +08:00
|
|
|
};
|
2021-05-18 04:25:07 +08:00
|
|
|
const startUserTyping = _.throttle(
|
|
|
|
chatId => makeCall('startUserTyping', chatId),
|
|
|
|
START_TYPING_THROTTLE_INTERVAL,
|
|
|
|
);
|
2019-08-22 05:56:32 +08:00
|
|
|
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;
|