bigbluebutton-Github/bigbluebutton-html5/imports/api/group-chat-msg/server/modifiers/addBulkGroupChatMsgs.js
Daniel Molkentin fa5aa182fe fix: do not escape text twice
The refactoring in 838accf015 incorrectly
replaced the wrong parseMessage function in addBulkGroupChatMsgs.js

This bug is only triggered when the option public.chat.bufferChatInsertsMs != 0.
2023-08-02 18:48:22 +02:00

48 lines
1.2 KiB
JavaScript

import { GroupChatMsg } from '/imports/api/group-chat-msg';
import GroupChat from '/imports/api/group-chat';
import Logger from '/imports/startup/server/logger';
import flat from 'flat';
import { parseMessage } from './addGroupChatMsg';
export default async function addBulkGroupChatMsgs(msgs) {
if (!msgs.length) return;
const mappedMsgs = msgs
.map(({ chatId, meetingId, msg }) => {
const {
sender,
...restMsg
} = msg;
return {
_id: new Mongo.ObjectID()._str,
...restMsg,
meetingId,
chatId,
message: parseMessage(msg.message),
sender: sender.id,
senderName: sender.name,
senderRole: sender.role,
};
})
.map((el) => flat(el, { safe: true }))
.map((msg)=>{
const groupChat = GroupChat.findOne({ meetingId: msg.meetingId, chatId: msg.chatId });
return {
...msg,
participants: [...groupChat.users],
};
});
try {
const { insertedCount } = await GroupChatMsg.rawCollection().insertMany(mappedMsgs);
msgs.length = 0;
if (insertedCount) {
Logger.info(`Inserted ${insertedCount} messages`);
}
} catch (err) {
Logger.error(`Error on bulk insert. ${err}`);
}
}