2019-08-08 23:12:53 +08:00
|
|
|
import { GroupChatMsg } from '/imports/api/group-chat-msg';
|
2018-03-10 02:42:14 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
2022-03-24 04:11:01 +08:00
|
|
|
import addSystemMsg from '/imports/api/group-chat-msg/server/modifiers/addSystemMsg';
|
2022-11-22 00:07:30 +08:00
|
|
|
import clearChatHasMessages from '/imports/api/users-persistent-data/server/modifiers/clearChatHasMessages';
|
2018-03-10 02:42:14 +08:00
|
|
|
|
|
|
|
export default function clearGroupChatMsg(meetingId, chatId) {
|
2018-08-03 22:03:16 +08:00
|
|
|
const CHAT_CONFIG = Meteor.settings.public.chat;
|
|
|
|
const PUBLIC_CHAT_SYSTEM_ID = CHAT_CONFIG.system_userid;
|
|
|
|
const PUBLIC_GROUP_CHAT_ID = CHAT_CONFIG.public_group_id;
|
|
|
|
const CHAT_CLEAR_MESSAGE = CHAT_CONFIG.system_messages_keys.chat_clear;
|
2021-02-10 21:14:30 +08:00
|
|
|
const SYSTEM_CHAT_TYPE = CHAT_CONFIG.type_system;
|
2018-08-03 22:03:16 +08:00
|
|
|
|
2018-03-10 02:42:14 +08:00
|
|
|
if (chatId) {
|
2020-11-25 04:44:13 +08:00
|
|
|
try {
|
|
|
|
const numberAffected = GroupChatMsg.remove({ meetingId, chatId });
|
|
|
|
|
|
|
|
if (numberAffected) {
|
|
|
|
Logger.info(`Cleared GroupChatMsg (${meetingId}, ${chatId})`);
|
|
|
|
const clearMsg = {
|
2021-02-10 21:14:30 +08:00
|
|
|
id: `${SYSTEM_CHAT_TYPE}-${CHAT_CLEAR_MESSAGE}`,
|
2020-11-25 04:44:13 +08:00
|
|
|
timestamp: Date.now(),
|
|
|
|
correlationId: `${PUBLIC_CHAT_SYSTEM_ID}-${Date.now()}`,
|
|
|
|
sender: {
|
|
|
|
id: PUBLIC_CHAT_SYSTEM_ID,
|
|
|
|
name: '',
|
|
|
|
},
|
|
|
|
message: CHAT_CLEAR_MESSAGE,
|
|
|
|
};
|
2022-03-24 04:11:01 +08:00
|
|
|
addSystemMsg(meetingId, PUBLIC_GROUP_CHAT_ID, clearMsg);
|
2022-11-22 00:07:30 +08:00
|
|
|
clearChatHasMessages(meetingId, chatId);
|
2020-11-25 04:44:13 +08:00
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Error on clearing GroupChat (${meetingId}, ${chatId}). ${err}`);
|
|
|
|
}
|
2019-02-15 04:18:06 +08:00
|
|
|
return true;
|
2018-03-10 02:42:14 +08:00
|
|
|
}
|
|
|
|
|
2018-08-03 01:23:20 +08:00
|
|
|
if (meetingId) {
|
2020-11-25 04:44:13 +08:00
|
|
|
try {
|
|
|
|
const numberAffected = GroupChatMsg.remove({ meetingId });
|
2018-08-03 01:23:20 +08:00
|
|
|
|
2020-11-25 04:44:13 +08:00
|
|
|
if (numberAffected) {
|
|
|
|
Logger.info(`Cleared GroupChatMsg (${meetingId})`);
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Error on clearing GroupChatMsg (${meetingId}). ${err}`);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
const numberAffected = GroupChatMsg.remove({ chatId: { $eq: PUBLIC_GROUP_CHAT_ID } });
|
|
|
|
|
|
|
|
if (numberAffected) {
|
2022-11-22 00:07:30 +08:00
|
|
|
clearChatHasMessages(meetingId, chatId=PUBLIC_GROUP_CHAT_ID);
|
|
|
|
|
2020-11-25 04:44:13 +08:00
|
|
|
Logger.info('Cleared GroupChatMsg (all)');
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Error on clearing GroupChatMsg (all). ${err}`);
|
|
|
|
}
|
|
|
|
}
|
2018-03-10 02:42:14 +08:00
|
|
|
}
|