Handle chat messages in sync way

This commit is contained in:
Joao Siebel 2020-11-18 18:09:38 -03:00
parent 468725c386
commit 4a88d0a6db
2 changed files with 9 additions and 13 deletions

View File

@ -8,5 +8,5 @@ export default function handleGroupChatMsgBroadcast({ body }, meetingId) {
check(chatId, String);
check(msg, Object);
return addGroupChatMsg(meetingId, chatId, msg);
addGroupChatMsg(meetingId, chatId, msg);
}

View File

@ -47,19 +47,15 @@ export default function addGroupChatMsg(meetingId, chatId, msg) {
$set: flat(msgDocument, { safe: true }),
};
const cb = (err, numChanged) => {
if (err) {
return Logger.error(`Adding group-chat-msg to collection: ${err}`);
}
const { insertedId } = numChanged;
try {
const { insertedId } = GroupChatMsg.upsert(selector, modifier);
if (insertedId) {
return Logger.info(`Added group-chat-msg msgId=${msg.id} chatId=${chatId} meetingId=${meetingId}`);
Logger.info(`Added group-chat-msg msgId=${msg.id} chatId=${chatId} meetingId=${meetingId}`);
} else {
Logger.info(`Upserted group-chat-msg msgId=${msg.id} chatId=${chatId} meetingId=${meetingId}`);
}
return Logger.info(`Upserted group-chat-msg msgId=${msg.id} chatId=${chatId} meetingId=${meetingId}`);
};
return GroupChatMsg.upsert(selector, modifier, cb);
} catch (err) {
Logger.error(`Adding group-chat-msg to collection: ${err}`);
}
}