2021-12-11 03:13:26 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
2022-01-28 02:45:04 +08:00
|
|
|
import UsersPersistentData from '/imports/api/users-persistent-data';
|
2021-12-11 03:13:26 +08:00
|
|
|
|
2022-11-22 00:07:30 +08:00
|
|
|
const CHAT_CONFIG = Meteor.settings.public.chat;
|
|
|
|
const PUBLIC_GROUP_CHAT_KEY = CHAT_CONFIG.public_group_id;
|
|
|
|
|
|
|
|
export default function changeHasMessages(hasMessages, userId, meetingId, chatId) {
|
2021-12-11 03:13:26 +08:00
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
userId,
|
|
|
|
};
|
|
|
|
|
2022-11-22 00:07:30 +08:00
|
|
|
const type = chatId === PUBLIC_GROUP_CHAT_KEY ? 'public' : 'private';
|
|
|
|
|
2021-12-11 03:13:26 +08:00
|
|
|
const modifier = {
|
|
|
|
$set: {
|
2022-11-22 00:07:30 +08:00
|
|
|
[`shouldPersist.hasMessages.${type}`]: hasMessages,
|
2021-12-11 03:13:26 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
2022-01-28 02:45:04 +08:00
|
|
|
const numberAffected = UsersPersistentData.update(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}`);
|
|
|
|
}
|
|
|
|
}
|