From 38c87c7f75f00becea70bd4f720a5cd177774aa8 Mon Sep 17 00:00:00 2001 From: Anton Georgiev Date: Tue, 12 Dec 2017 11:19:24 -0500 Subject: [PATCH] poll voted - drop requesterId and rename event --- .../imports/api/polls/server/eventHandlers.js | 2 +- .../api/polls/server/handlers/userVoted.js | 17 +++++++++++++---- .../api/polls/server/methods/publishVote.js | 5 +++++ .../api/polls/server/modifiers/updateVotes.js | 14 ++++---------- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/bigbluebutton-html5/imports/api/polls/server/eventHandlers.js b/bigbluebutton-html5/imports/api/polls/server/eventHandlers.js index 0f3062c9ff..91bf131a75 100644 --- a/bigbluebutton-html5/imports/api/polls/server/eventHandlers.js +++ b/bigbluebutton-html5/imports/api/polls/server/eventHandlers.js @@ -7,4 +7,4 @@ import handleUserVoted from './handlers/userVoted'; RedisPubSub.on('PollShowResultEvtMsg', handlePollPublished); RedisPubSub.on('PollStartedEvtMsg', handlePollStarted); RedisPubSub.on('PollStoppedEvtMsg', handlePollStopped); -RedisPubSub.on('UserRespondedToPollEvtMsg', handleUserVoted); +RedisPubSub.on('PollUpdatedEvtMsg', handleUserVoted); diff --git a/bigbluebutton-html5/imports/api/polls/server/handlers/userVoted.js b/bigbluebutton-html5/imports/api/polls/server/handlers/userVoted.js index 5b80a46d28..d73d8b6790 100644 --- a/bigbluebutton-html5/imports/api/polls/server/handlers/userVoted.js +++ b/bigbluebutton-html5/imports/api/polls/server/handlers/userVoted.js @@ -3,11 +3,20 @@ import updateVotes from '../modifiers/updateVotes'; export default function userVoted({ body }, meetingId) { const { poll } = body; - const { presenterId } = body; check(meetingId, String); - check(poll, Object); - check(presenterId, String); + check(poll, { + id: String, + answers: [ + { + id: Number, + key: String, + numVotes: Number, + }, + ], + numRespondents: Number, + numResponders: Number, + }); - return updateVotes(poll, meetingId, presenterId); + return updateVotes(poll, meetingId); } diff --git a/bigbluebutton-html5/imports/api/polls/server/methods/publishVote.js b/bigbluebutton-html5/imports/api/polls/server/methods/publishVote.js index bc59d38e06..011f21411e 100644 --- a/bigbluebutton-html5/imports/api/polls/server/methods/publishVote.js +++ b/bigbluebutton-html5/imports/api/polls/server/methods/publishVote.js @@ -10,6 +10,11 @@ export default function publishVote(credentials, id, pollAnswerId) { // TODO dis const { meetingId, requesterUserId } = credentials; + /* + We keep an array of people who were in the meeting at the time the poll + was started. The poll is published to them only. + Once they vote - their ID is removed and they cannot see the poll anymore + */ const currentPoll = Polls.findOne({ users: requesterUserId, meetingId, diff --git a/bigbluebutton-html5/imports/api/polls/server/modifiers/updateVotes.js b/bigbluebutton-html5/imports/api/polls/server/modifiers/updateVotes.js index 3cb37bd1da..30815aafa1 100644 --- a/bigbluebutton-html5/imports/api/polls/server/modifiers/updateVotes.js +++ b/bigbluebutton-html5/imports/api/polls/server/modifiers/updateVotes.js @@ -3,19 +3,17 @@ import { check } from 'meteor/check'; import Logger from '/imports/startup/server/logger'; import flat from 'flat'; -export default function updateVotes(poll, meetingId, requesterId) { +export default function updateVotes(poll, meetingId) { check(meetingId, String); - check(requesterId, String); check(poll, Object); const { id, answers, + numResponders, + numRespondents, } = poll; - const { numResponders } = poll; - const { numRespondents } = poll; - check(id, String); check(answers, Array); @@ -24,15 +22,11 @@ export default function updateVotes(poll, meetingId, requesterId) { const selector = { meetingId, - requester: requesterId, id, }; const modifier = { - $set: Object.assign( - { requester: requesterId }, - flat(poll, { safe: true }), - ), + $set: flat(poll, { safe: true }), }; const cb = (err) => {