bigbluebutton-Github/bigbluebutton-html5/imports/api/polls/server/handlers/sendPollChatMsg.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

2021-02-19 21:57:11 +08:00
import addSystemMsg from '../../../group-chat-msg/server/modifiers/addSystemMsg';
2022-06-14 00:08:44 +08:00
import caseInsensitiveReducer from '/imports/utils/caseInsensitiveReducer';
2021-02-19 21:57:11 +08:00
export default function sendPollChatMsg({ body }, meetingId) {
const { poll } = body;
const CHAT_CONFIG = Meteor.settings.public.chat;
const PUBLIC_GROUP_CHAT_ID = CHAT_CONFIG.public_group_id;
const PUBLIC_CHAT_SYSTEM_ID = CHAT_CONFIG.system_userid;
const CHAT_POLL_RESULTS_MESSAGE = CHAT_CONFIG.system_messages_keys.chat_poll_result;
const SYSTEM_CHAT_TYPE = CHAT_CONFIG.type_system;
const pollResultData = poll;
2022-06-14 00:08:44 +08:00
const answers = pollResultData.answers.reduce(caseInsensitiveReducer, []);
const extra = {
type: 'poll',
2022-06-14 00:08:44 +08:00
pollResultData: {
...pollResultData,
answers,
},
};
2021-02-19 21:57:11 +08:00
const payload = {
id: `${SYSTEM_CHAT_TYPE}-${CHAT_POLL_RESULTS_MESSAGE}`,
timestamp: Date.now(),
correlationId: `${PUBLIC_CHAT_SYSTEM_ID}-${Date.now()}`,
sender: {
id: PUBLIC_CHAT_SYSTEM_ID,
name: '',
},
message: '',
extra,
2021-02-19 21:57:11 +08:00
};
return addSystemMsg(meetingId, PUBLIC_GROUP_CHAT_ID, payload);
}