diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/polls/RespondToPollReqMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/polls/RespondToPollReqMsgHdlr.scala index a7763e9220..79e8f01032 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/polls/RespondToPollReqMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/polls/RespondToPollReqMsgHdlr.scala @@ -45,27 +45,31 @@ trait RespondToPollReqMsgHdlr { bus.outGW.send(msgEvent) } - for { - (pollId: String, updatedPoll: SimplePollResultOutVO) <- Polls.handleRespondToPollReqMsg(msg.header.userId, msg.body.pollId, - msg.body.questionId, msg.body.answerIds, liveMeeting) - } yield { - broadcastPollUpdatedEvent(msg, pollId, updatedPoll) + if (Polls.checkUserResponded(msg.body.pollId, msg.header.userId, liveMeeting.polls) == false) { for { - poll <- Polls.getPoll(pollId, liveMeeting.polls) + (pollId: String, updatedPoll: SimplePollResultOutVO) <- Polls.handleRespondToPollReqMsg(msg.header.userId, msg.body.pollId, + msg.body.questionId, msg.body.answerIds, liveMeeting) } yield { + broadcastPollUpdatedEvent(msg, pollId, updatedPoll) for { - answerId <- msg.body.answerIds + poll <- Polls.getPoll(pollId, liveMeeting.polls) } yield { - val answerText = poll.questions(0).answers.get(answerId).key - broadcastUserRespondedToPollRecordMsg(msg, pollId, answerId, answerText, poll.isSecret) + for { + answerId <- msg.body.answerIds + } yield { + val answerText = poll.questions(0).answers.get(answerId).key + broadcastUserRespondedToPollRecordMsg(msg, pollId, answerId, answerText, poll.isSecret) + } + } + + for { + presenter <- Users2x.findPresenter(liveMeeting.users2x) + } yield { + broadcastUserRespondedToPollRespMsg(msg, pollId, msg.body.answerIds, presenter.intId) } } - - for { - presenter <- Users2x.findPresenter(liveMeeting.users2x) - } yield { - broadcastUserRespondedToPollRespMsg(msg, pollId, msg.body.answerIds, presenter.intId) - } + } else { + log.info("Ignoring answer from user {} once user already responded poll {} in meeting {}", msg.header.userId, msg.body.pollId, msg.header.meetingId) } } } diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/polls/RespondToTypedPollReqMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/polls/RespondToTypedPollReqMsgHdlr.scala index 1b5187c684..420d18e8c5 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/polls/RespondToTypedPollReqMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/polls/RespondToTypedPollReqMsgHdlr.scala @@ -34,17 +34,23 @@ trait RespondToTypedPollReqMsgHdlr { bus.outGW.send(msgEvent) } - for { - (pollId: String, updatedPoll: SimplePollResultOutVO) <- Polls.handleRespondToTypedPollReqMsg(msg.header.userId, msg.body.pollId, - msg.body.questionId, msg.body.answer, liveMeeting) - } yield { - broadcastPollUpdatedEvent(msg, pollId, updatedPoll) - + if (Polls.isResponsePollType(msg.body.pollId, liveMeeting.polls) && + Polls.checkUserResponded(msg.body.pollId, msg.header.userId, liveMeeting.polls) == false && + Polls.checkUserAddedQuestion(msg.body.pollId, msg.header.userId, liveMeeting.polls) == false) { for { - presenter <- Users2x.findPresenter(liveMeeting.users2x) + (pollId: String, updatedPoll: SimplePollResultOutVO) <- Polls.handleRespondToTypedPollReqMsg(msg.header.userId, msg.body.pollId, + msg.body.questionId, msg.body.answer, liveMeeting) } yield { - broadcastUserRespondedToTypedPollRespMsg(msg, pollId, msg.body.answer, presenter.intId) + broadcastPollUpdatedEvent(msg, pollId, updatedPoll) + + for { + presenter <- Users2x.findPresenter(liveMeeting.users2x) + } yield { + broadcastUserRespondedToTypedPollRespMsg(msg, pollId, msg.body.answer, presenter.intId) + } } + } else { + log.info("Ignoring typed answer from user {} once user already added an answer to this poll {} in meeting {}", msg.header.userId, msg.body.pollId, msg.header.meetingId) } } } diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/models/Polls.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/models/Polls.scala index db49411f0d..f6271bc62c 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/models/Polls.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/models/Polls.scala @@ -244,7 +244,7 @@ object Polls { private def handleRespondToTypedPoll(poll: SimplePollResultOutVO, requesterId: String, pollId: String, questionId: Int, answer: String, lm: LiveMeeting): Option[SimplePollResultOutVO] = { - addQuestionResponse(poll.id, questionId, answer, lm.polls) + addQuestionResponse(poll.id, questionId, answer, requesterId, lm.polls) for { updatedPoll <- getSimplePollResult(poll.id, lm.polls) } yield { @@ -407,6 +407,45 @@ object Polls { pvo } + def checkUserResponded(pollId: String, userId: String, polls: Polls): Boolean = { + polls.polls.get(pollId) match { + case Some(p) => { + if (p.getResponders().filter(p => p.userId == userId).length > 0) { + true + } else { + false + } + } + case None => false + } + } + + def checkUserAddedQuestion(pollId: String, userId: String, polls: Polls): Boolean = { + polls.polls.get(pollId) match { + case Some(p) => { + if (p.getTypedPollResponders().filter(responderId => responderId == userId).length > 0) { + true + } else { + false + } + } + case None => false + } + } + + def isResponsePollType(pollId: String, polls: Polls): Boolean = { + polls.polls.get(pollId) match { + case Some(p) => { + if (p.questions.filter(q => q.questionType == PollType.ResponsePollType).length > 0) { + true + } else { + false + } + } + case None => false + } + } + def showPollResult(pollId: String, polls: Polls) { polls.get(pollId) foreach { p => @@ -427,10 +466,13 @@ object Polls { } } - def addQuestionResponse(pollId: String, questionID: Int, answer: String, polls: Polls) { + def addQuestionResponse(pollId: String, questionID: Int, answer: String, requesterId: String, polls: Polls) { polls.polls.get(pollId) match { case Some(p) => { - p.addQuestionResponse(questionID, answer) + if (!p.getTypedPollResponders().contains(requesterId)) { + p.addTypedPollResponder(requesterId) + p.addQuestionResponse(questionID, answer) + } } case None => } @@ -597,6 +639,7 @@ class Poll(val id: String, val questions: Array[Question], val numRespondents: I private var _showResult: Boolean = false private var _numResponders: Int = 0 private var _responders = new ArrayBuffer[Responder]() + private var _respondersTypedPoll = new ArrayBuffer[String]() def showingResult() { _showResult = true } def showResult(): Boolean = { _showResult } @@ -613,6 +656,8 @@ class Poll(val id: String, val questions: Array[Question], val numRespondents: I def addResponder(responder: Responder) { _responders += (responder) } def getResponders(): ArrayBuffer[Responder] = { return _responders } + def addTypedPollResponder(responderId: String) { _respondersTypedPoll += (responderId) } + def getTypedPollResponders(): ArrayBuffer[String] = { return _respondersTypedPoll } def hasResponses(): Boolean = { questions.foreach(q => {