bigbluebutton-Github/bigbluebutton-html5/imports/api/users-persistent-data/server/modifiers/changeHasMessages.js

31 lines
850 B
JavaScript
Raw Normal View History

2021-12-11 03:13:26 +08:00
import Logger from '/imports/startup/server/logger';
import UsersPersistentData from '/imports/api/users-persistent-data';
2021-12-11 03:13:26 +08:00
const CHAT_CONFIG = Meteor.settings.public.chat;
const PUBLIC_GROUP_CHAT_KEY = CHAT_CONFIG.public_group_id;
export default async function changeHasMessages(hasMessages, userId, meetingId, chatId) {
2021-12-11 03:13:26 +08:00
const selector = {
meetingId,
userId,
};
const type = chatId === PUBLIC_GROUP_CHAT_KEY ? 'public' : 'private';
2021-12-11 03:13:26 +08:00
const modifier = {
$set: {
[`shouldPersist.hasMessages.${type}`]: hasMessages,
2021-12-11 03:13:26 +08:00
},
};
try {
const numberAffected = await UsersPersistentData.updateAsync(selector, modifier);
2021-12-11 03:13:26 +08:00
if (numberAffected) {
Logger.info(`Changed hasMessages=${hasMessages} id=${userId} meeting=${meetingId}`);
}
} catch (err) {
Logger.error(`Change hasMessages error: ${err}`);
}
}