2018-03-10 02:42:14 +08:00
|
|
|
import { check } from 'meteor/check';
|
2023-03-02 02:13:29 +08:00
|
|
|
import throttle from 'lodash.throttle';
|
2018-03-10 02:42:14 +08:00
|
|
|
import addGroupChatMsg from '../modifiers/addGroupChatMsg';
|
2020-11-30 22:27:26 +08:00
|
|
|
import addBulkGroupChatMsgs from '../modifiers/addBulkGroupChatMsgs';
|
|
|
|
|
|
|
|
const { bufferChatInsertsMs } = Meteor.settings.public.chat;
|
|
|
|
|
|
|
|
const msgBuffer = [];
|
|
|
|
|
2023-03-02 02:13:29 +08:00
|
|
|
const bulkFn = throttle(addBulkGroupChatMsgs, bufferChatInsertsMs);
|
2018-03-10 02:42:14 +08:00
|
|
|
|
|
|
|
export default function handleGroupChatMsgBroadcast({ body }, meetingId) {
|
|
|
|
const { chatId, msg } = body;
|
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(chatId, String);
|
|
|
|
check(msg, Object);
|
|
|
|
|
2020-11-30 22:27:26 +08:00
|
|
|
if (bufferChatInsertsMs) {
|
|
|
|
msgBuffer.push({ meetingId, chatId, msg });
|
|
|
|
bulkFn(msgBuffer);
|
|
|
|
} else {
|
|
|
|
addGroupChatMsg(meetingId, chatId, msg);
|
|
|
|
}
|
2018-03-10 02:42:14 +08:00
|
|
|
}
|