2022-11-22 00:07:30 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
import UsersPersistentData from '/imports/api/users-persistent-data';
|
|
|
|
|
|
|
|
const CHAT_CONFIG = Meteor.settings.public.chat;
|
|
|
|
const PUBLIC_GROUP_CHAT_KEY = CHAT_CONFIG.public_group_id;
|
|
|
|
|
2023-03-20 21:21:34 +08:00
|
|
|
export default async function clearChatHasMessages(meetingId, chatId) {
|
2022-11-22 00:07:30 +08:00
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
};
|
|
|
|
|
|
|
|
const type = chatId === PUBLIC_GROUP_CHAT_KEY ? 'public' : 'private';
|
2023-03-20 21:21:34 +08:00
|
|
|
|
2022-11-22 00:07:30 +08:00
|
|
|
const modifier = {
|
|
|
|
$set: {
|
|
|
|
[`shouldPersist.hasMessages.${type}`]: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
2023-03-20 21:21:34 +08:00
|
|
|
const numberAffected = await UsersPersistentData
|
|
|
|
.updateAsync(selector, modifier, { multi: true });
|
2022-11-22 00:07:30 +08:00
|
|
|
|
|
|
|
if (numberAffected) {
|
|
|
|
Logger.info(`Cleared hasMessages meeting=${meetingId}`);
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Clear hasMessages error: ${err}`);
|
|
|
|
}
|
|
|
|
}
|