2017-06-27 20:40:28 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
import { check } from 'meteor/check';
|
2017-10-12 10:00:28 +08:00
|
|
|
import Users from '/imports/api/users';
|
2021-10-14 22:11:37 +08:00
|
|
|
import sendStatusChatMsg from '../methods/sendStatusChatMsg';
|
2017-06-27 20:40:28 +08:00
|
|
|
|
2023-03-15 21:18:31 +08:00
|
|
|
export default async function handleEmojiStatus({ body }, meetingId) {
|
2017-07-13 21:15:42 +08:00
|
|
|
const { userId, emoji } = body;
|
2017-06-27 20:40:28 +08:00
|
|
|
|
|
|
|
check(userId, String);
|
2017-07-13 21:15:42 +08:00
|
|
|
check(emoji, String);
|
2017-06-27 20:40:28 +08:00
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
userId,
|
|
|
|
};
|
|
|
|
|
|
|
|
const modifier = {
|
|
|
|
$set: {
|
2017-07-26 22:09:07 +08:00
|
|
|
emojiTime: (new Date()).getTime(),
|
|
|
|
emoji,
|
2017-06-27 20:40:28 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-11-23 21:13:46 +08:00
|
|
|
try {
|
2021-10-14 22:11:37 +08:00
|
|
|
// must be called before modifying the users collection, because it
|
|
|
|
// needs to be consulted in order to know the previous emoji
|
|
|
|
sendStatusChatMsg(meetingId, userId, emoji);
|
|
|
|
|
|
|
|
const numberAffected = Users.update(selector, modifier);
|
2017-06-27 20:40:28 +08:00
|
|
|
|
2020-11-23 21:13:46 +08:00
|
|
|
if (numberAffected) {
|
2019-08-19 20:56:21 +08:00
|
|
|
Logger.info(`Assigned user emoji status ${emoji} id=${userId} meeting=${meetingId}`);
|
2017-06-27 20:40:28 +08:00
|
|
|
}
|
2020-11-23 21:13:46 +08:00
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Assigning user emoji status: ${err}`);
|
|
|
|
}
|
2017-06-27 20:40:28 +08:00
|
|
|
}
|