bigbluebutton-Github/bigbluebutton-html5/imports/api/polls/server/methods/publishVote.js

53 lines
1.6 KiB
JavaScript
Raw Normal View History

2016-10-21 21:21:09 +08:00
import { publish } from '/imports/api/common/server/helpers';
import { isAllowedTo } from '/imports/startup/server/userPermissions';
import { appendMessageHeader } from '/imports/api/common/server/helpers';
import Polls from '/imports/api/polls';
import { logger } from '/imports/startup/server/logger';
export default function publishVote(credentials, pollId, pollAnswerId) { //TODO discuss location
const REDIS_CONFIG = Meteor.settings.redis;
if (isAllowedTo('subscribePoll', credentials)) {
const { meetingId, requesterUserId, requesterToken } = credentials;
const eventName = 'vote_poll_user_request_message';
const result = Polls.findOne({
users: requesterUserId,
meetingId: meetingId,
'poll.answers.id': pollAnswerId,
'poll.id': pollId,
});
if ((meetingId != null) &&
(result.meetingId != null) &&
(requesterUserId != null) &&
(pollAnswerId != null)) {
let message = {
payload: {
meeting_id: result.meetingId,
user_id: requesterUserId,
poll_id: result.poll.id,
question_id: 0,
answer_id: pollAnswerId,
},
};
const selector = {
2016-10-21 21:21:09 +08:00
users: requesterUserId,
meetingId: meetingId,
'poll.answers.id': pollAnswerId,
};
const modifier = {
2016-10-21 21:21:09 +08:00
$pull: {
users: requesterUserId,
},
};
Polls.update(selector, modifier);
2016-10-21 21:21:09 +08:00
message = appendMessageHeader(eventName, message);
logger.info('publishing Poll response to redis');
return publish(REDIS_CONFIG.channels.toBBBApps.polling, message);
}
}
}