2018-09-25 06:43:54 +08:00
|
|
|
import RedisPubSub from '/imports/startup/server/redis';
|
|
|
|
import Polls from '/imports/api/polls';
|
2019-05-10 02:41:15 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
2020-02-07 04:47:28 +08:00
|
|
|
import { extractCredentials } from '/imports/api/common/server/helpers';
|
2021-03-17 00:15:41 +08:00
|
|
|
import { check } from 'meteor/check';
|
2018-09-25 06:43:54 +08:00
|
|
|
|
2023-03-07 21:47:43 +08:00
|
|
|
export default async function publishPoll() {
|
2018-09-25 06:43:54 +08:00
|
|
|
const REDIS_CONFIG = Meteor.settings.private.redis;
|
|
|
|
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
|
|
|
const EVENT_NAME = 'ShowPollResultReqMsg';
|
|
|
|
|
2021-05-05 22:12:36 +08:00
|
|
|
try {
|
|
|
|
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
2021-03-17 00:15:41 +08:00
|
|
|
|
2021-05-05 22:12:36 +08:00
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
2021-03-17 00:15:41 +08:00
|
|
|
|
2023-03-07 21:47:43 +08:00
|
|
|
const poll = await Polls.findOneAsync({ meetingId }); // TODO--send pollid from client
|
2021-05-05 22:12:36 +08:00
|
|
|
if (!poll) {
|
|
|
|
Logger.error(`Attempted to publish inexisting poll for meetingId: ${meetingId}`);
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-25 06:43:54 +08:00
|
|
|
|
2021-05-05 22:12:36 +08:00
|
|
|
RedisPubSub.publishUserMessage(
|
|
|
|
CHANNEL,
|
|
|
|
EVENT_NAME,
|
|
|
|
meetingId,
|
|
|
|
requesterUserId,
|
|
|
|
({ requesterId: requesterUserId, pollId: poll.id }),
|
|
|
|
);
|
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Exception while invoking method publishPoll ${err.stack}`);
|
|
|
|
}
|
2023-03-07 21:47:43 +08:00
|
|
|
//In this case we return true because
|
|
|
|
//lint asks for async functions to return some value.
|
|
|
|
return true;
|
2018-09-25 06:43:54 +08:00
|
|
|
}
|