2021-09-10 04:49:15 +08:00
|
|
|
import React from 'react';
|
2023-03-02 21:25:08 +08:00
|
|
|
import { throttle } from '/imports/utils/throttle';
|
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';
|
2021-09-11 04:48:52 +08:00
|
|
|
import { layoutSelect } from '../../layout/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) => {
|
2021-09-11 04:48:52 +08:00
|
|
|
const idChatOpen = layoutSelect((i) => i.idChatOpen);
|
2021-09-10 04:49:15 +08:00
|
|
|
|
2021-05-18 04:25:07 +08:00
|
|
|
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
|
|
|
};
|
2023-03-02 02:13:29 +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,
|
|
|
|
);
|
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;
|