2018-03-10 02:42:14 +08:00
|
|
|
import { check } from 'meteor/check';
|
2023-03-02 21:25:08 +08:00
|
|
|
import { throttle } from '/imports/utils/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
|
|
|
|
2023-03-14 02:28:06 +08:00
|
|
|
export default async function handleGroupChatMsgBroadcast({ body }, meetingId) {
|
2018-03-10 02:42:14 +08:00
|
|
|
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 {
|
2023-03-14 02:28:06 +08:00
|
|
|
await addGroupChatMsg(meetingId, chatId, msg);
|
2020-11-30 22:27:26 +08:00
|
|
|
}
|
2018-03-10 02:42:14 +08:00
|
|
|
}
|