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(chatId, String);
check(msg, Object); 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 }), $set: flat(msgDocument, { safe: true }),
}; };
const cb = (err, numChanged) => { try {
if (err) { const { insertedId } = GroupChatMsg.upsert(selector, modifier);
return Logger.error(`Adding group-chat-msg to collection: ${err}`);
}
const { insertedId } = numChanged;
if (insertedId) { 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}`);
}
} catch (err) {
Logger.error(`Adding group-chat-msg to collection: ${err}`);
} }
return Logger.info(`Upserted group-chat-msg msgId=${msg.id} chatId=${chatId} meetingId=${meetingId}`);
};
return GroupChatMsg.upsert(selector, modifier, cb);
} }