2018-09-24 06:57:03 +08:00
|
|
|
import RedisPubSub from '/imports/startup/server/redis';
|
|
|
|
import { check } from 'meteor/check';
|
2020-02-07 04:47:28 +08:00
|
|
|
import { extractCredentials } from '/imports/api/common/server/helpers';
|
2018-09-24 06:57:03 +08:00
|
|
|
|
2021-03-07 22:12:49 +08:00
|
|
|
export default function startPoll(pollType, pollId, question, isMultipleResponse, answers) {
|
2018-09-24 06:57:03 +08:00
|
|
|
const REDIS_CONFIG = Meteor.settings.private.redis;
|
|
|
|
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
|
|
|
|
2018-09-24 06:20:20 +08:00
|
|
|
let EVENT_NAME = 'StartPollReqMsg';
|
2018-09-24 06:57:03 +08:00
|
|
|
|
2020-02-07 04:47:28 +08:00
|
|
|
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
|
|
|
|
2021-03-17 00:15:41 +08:00
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
2018-09-24 06:57:03 +08:00
|
|
|
check(pollId, String);
|
|
|
|
check(pollType, String);
|
|
|
|
|
|
|
|
const payload = {
|
|
|
|
requesterId: requesterUserId,
|
|
|
|
pollId: `${pollId}/${new Date().getTime()}`,
|
|
|
|
pollType,
|
2020-09-21 20:07:36 +08:00
|
|
|
question,
|
2021-02-08 17:57:39 +08:00
|
|
|
isMultipleResponse,
|
2018-09-24 06:57:03 +08:00
|
|
|
};
|
|
|
|
|
2018-09-24 06:20:20 +08:00
|
|
|
if (pollType === 'custom') {
|
|
|
|
EVENT_NAME = 'StartCustomPollReqMsg';
|
|
|
|
check(answers, Array);
|
|
|
|
payload.answers = answers;
|
|
|
|
}
|
|
|
|
|
2018-09-24 06:57:03 +08:00
|
|
|
return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
|
|
|
|
}
|