From 7bedcb08e5d93c2654691ac8ae9dcd13b2c7c33c Mon Sep 17 00:00:00 2001 From: germanocaumo <germanocaumo@gmail.com> Date: Fri, 11 Jun 2021 16:55:53 +0000 Subject: [PATCH] fix(poll): don't translate user/presenter typed answers When the answer is not default (Custom or UserResponse), don't translate the answers. --- .../org/bigbluebutton/core/models/Polls.scala | 3 +- .../common2/domain/Meeting2x.scala | 2 +- .../api/polls/server/handlers/userVoted.js | 1 + .../api/polls/server/methods/startPoll.js | 4 +-- .../imports/ui/components/poll/component.jsx | 2 ++ .../imports/ui/components/poll/container.jsx | 6 ++-- .../components/poll/live-result/component.jsx | 10 ++++--- .../imports/ui/components/poll/service.js | 2 +- .../ui/components/polling/component.jsx | 8 +++-- .../ui/components/polling/container.jsx | 1 + .../presentation-toolbar/container.jsx | 3 +- .../whiteboard/annotations/poll/component.jsx | 30 +++++-------------- 12 files changed, 34 insertions(+), 38 deletions(-) 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 aba3186cdc..a1ff8bd799 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 @@ -255,6 +255,7 @@ object Polls { shape += "numRespondents" -> new Integer(result.numRespondents) shape += "numResponders" -> new Integer(result.numResponders) shape += "type" -> WhiteboardKeyUtil.POLL_RESULT_TYPE + shape += "pollType" -> result.questionType shape += "id" -> result.id shape += "status" -> WhiteboardKeyUtil.DRAW_END_STATUS @@ -644,7 +645,7 @@ class Poll(val id: String, val questions: Array[Question], val numRespondents: I } def toSimplePollResultOutVO(): SimplePollResultOutVO = { - new SimplePollResultOutVO(id, questions(0).text, questions(0).toSimpleVotesOutVO(), numRespondents, _numResponders) + new SimplePollResultOutVO(id, questions(0).questionType, questions(0).text, questions(0).toSimpleVotesOutVO(), numRespondents, _numResponders) } } diff --git a/bbb-common-message/src/main/scala/org/bigbluebutton/common2/domain/Meeting2x.scala b/bbb-common-message/src/main/scala/org/bigbluebutton/common2/domain/Meeting2x.scala index 81cbd48e81..7076bdfe8c 100755 --- a/bbb-common-message/src/main/scala/org/bigbluebutton/common2/domain/Meeting2x.scala +++ b/bbb-common-message/src/main/scala/org/bigbluebutton/common2/domain/Meeting2x.scala @@ -77,7 +77,7 @@ case class Meeting2x(defaultProps: DefaultProps, meetingStatus: MeetingStatus) case class SimpleAnswerOutVO(id: Int, key: String) case class SimplePollOutVO(id: String, answers: Array[SimpleAnswerOutVO]) case class SimpleVoteOutVO(id: Int, key: String, numVotes: Int) -case class SimplePollResultOutVO(id: String, questionText: Option[String], answers: Array[SimpleVoteOutVO], numRespondents: Int, numResponders: Int) +case class SimplePollResultOutVO(id: String, questionType: String, questionText: Option[String], answers: Array[SimpleVoteOutVO], numRespondents: Int, numResponders: Int) case class Responder(userId: String, name: String) case class AnswerVO(id: Int, key: String, text: Option[String], responders: Option[Array[Responder]]) case class QuestionVO(id: Int, questionType: String, multiResponse: Boolean, questionText: Option[String], answers: Option[Array[AnswerVO]]) diff --git a/bigbluebutton-html5/imports/api/polls/server/handlers/userVoted.js b/bigbluebutton-html5/imports/api/polls/server/handlers/userVoted.js index e4efe88860..b82087d8bb 100644 --- a/bigbluebutton-html5/imports/api/polls/server/handlers/userVoted.js +++ b/bigbluebutton-html5/imports/api/polls/server/handlers/userVoted.js @@ -7,6 +7,7 @@ export default function userVoted({ body }, meetingId) { check(meetingId, String); check(poll, { id: String, + questionType: String, questionText: String, answers: [ { diff --git a/bigbluebutton-html5/imports/api/polls/server/methods/startPoll.js b/bigbluebutton-html5/imports/api/polls/server/methods/startPoll.js index 728fbab6d7..f37caca858 100644 --- a/bigbluebutton-html5/imports/api/polls/server/methods/startPoll.js +++ b/bigbluebutton-html5/imports/api/polls/server/methods/startPoll.js @@ -3,7 +3,7 @@ import { check } from 'meteor/check'; import { extractCredentials } from '/imports/api/common/server/helpers'; import Logger from '/imports/startup/server/logger'; -export default function startPoll(pollType, pollId, question, answers) { +export default function startPoll(pollTypes, pollType, pollId, question, answers) { const REDIS_CONFIG = Meteor.settings.private.redis; const CHANNEL = REDIS_CONFIG.channels.toAkkaApps; let EVENT_NAME = 'StartPollReqMsg'; @@ -23,7 +23,7 @@ export default function startPoll(pollType, pollId, question, answers) { question, }; - if (pollType === 'custom') { + if (pollType === pollTypes.Custom) { EVENT_NAME = 'StartCustomPollReqMsg'; check(answers, Array); payload.answers = answers; diff --git a/bigbluebutton-html5/imports/ui/components/poll/component.jsx b/bigbluebutton-html5/imports/ui/components/poll/component.jsx index 7a75ee3b30..bc2352767e 100644 --- a/bigbluebutton-html5/imports/ui/components/poll/component.jsx +++ b/bigbluebutton-html5/imports/ui/components/poll/component.jsx @@ -351,6 +351,7 @@ class Poll extends Component { currentPoll, pollAnswerIds, usernames, + isDefaultPoll, } = this.props; return ( @@ -365,6 +366,7 @@ class Poll extends Component { currentPoll, pollAnswerIds, usernames, + isDefaultPoll, }} handleBackClick={this.handleBackClick} /> diff --git a/bigbluebutton-html5/imports/ui/components/poll/container.jsx b/bigbluebutton-html5/imports/ui/components/poll/container.jsx index 34a200b606..6cfdbb2fc3 100644 --- a/bigbluebutton-html5/imports/ui/components/poll/container.jsx +++ b/bigbluebutton-html5/imports/ui/components/poll/container.jsx @@ -35,9 +35,11 @@ export default withTracker(() => { const pollId = currentSlide ? currentSlide.id : PUBLIC_CHAT_KEY; - const startPoll = (type, question = '') => makeCall('startPoll', type, pollId, question); + const pollTypes = Service.pollTypes; - const startCustomPoll = (type, question = '', answers) => makeCall('startPoll', type, pollId, question, answers); + const startPoll = (type, question = '') => makeCall('startPoll', pollTypes, type, pollId, question); + + const startCustomPoll = (type, question = '', answers) => makeCall('startPoll', pollTypes, type, pollId, question, answers); const stopPoll = () => makeCall('stopPoll'); diff --git a/bigbluebutton-html5/imports/ui/components/poll/live-result/component.jsx b/bigbluebutton-html5/imports/ui/components/poll/live-result/component.jsx index a762390d20..aa7ec79beb 100644 --- a/bigbluebutton-html5/imports/ui/components/poll/live-result/component.jsx +++ b/bigbluebutton-html5/imports/ui/components/poll/live-result/component.jsx @@ -46,15 +46,17 @@ const getResponseString = (obj) => { class LiveResult extends PureComponent { static getDerivedStateFromProps(nextProps) { const { - currentPoll, intl, pollAnswerIds, usernames, + currentPoll, intl, pollAnswerIds, usernames, isDefaultPoll, } = nextProps; if (!currentPoll) return null; const { - answers, responses, users, numRespondents, + answers, responses, users, numRespondents, pollType } = currentPoll; + const defaultPoll = isDefaultPoll(pollType); + const currentPollQuestion = (currentPoll.question) ? currentPoll.question : ''; let userAnswers = responses @@ -85,7 +87,7 @@ class LiveResult extends PureComponent { <td className={styles.resultLeft}>{user.name}</td> <td data-test="receivedAnswer" className={styles.resultRight}> { - pollAnswerIds[formattedMessageIndex] + defaultPoll && pollAnswerIds[formattedMessageIndex] ? intl.formatMessage(pollAnswerIds[formattedMessageIndex]) : user.answer } @@ -110,7 +112,7 @@ class LiveResult extends PureComponent { <div className={styles.main} key={_.uniqueId('stats-')}> <div className={styles.left}> { - pollAnswerIds[formattedMessageIndex] + defaultPoll && pollAnswerIds[formattedMessageIndex] ? intl.formatMessage(pollAnswerIds[formattedMessageIndex]) : obj.key } diff --git a/bigbluebutton-html5/imports/ui/components/poll/service.js b/bigbluebutton-html5/imports/ui/components/poll/service.js index b161193ff0..a50f1c122e 100644 --- a/bigbluebutton-html5/imports/ui/components/poll/service.js +++ b/bigbluebutton-html5/imports/ui/components/poll/service.js @@ -23,7 +23,7 @@ const pollTypes = { A3: 'A-3', A4: 'A-4', A5: 'A-5', - Custom: 'custom', + Custom: 'CUSTOM', Response: 'R-', } diff --git a/bigbluebutton-html5/imports/ui/components/polling/component.jsx b/bigbluebutton-html5/imports/ui/components/polling/component.jsx index 21f782255c..51f776bad8 100644 --- a/bigbluebutton-html5/imports/ui/components/polling/component.jsx +++ b/bigbluebutton-html5/imports/ui/components/polling/component.jsx @@ -92,7 +92,8 @@ class Polling extends Component { handleVote, handleTypedVote, pollAnswerIds, - pollTypes + pollTypes, + isDefaultPoll, } = this.props; const { @@ -101,7 +102,8 @@ class Polling extends Component { if (!poll) return null; - const { stackOptions, answers, question } = poll; + const { stackOptions, answers, question, pollType } = poll; + const defaultPoll = isDefaultPoll(pollType); const pollAnswerStyles = { [styles.pollingAnswers]: true, @@ -144,7 +146,7 @@ class Polling extends Component { {poll.answers.map((pollAnswer) => { const formattedMessageIndex = pollAnswer.key.toLowerCase(); let label = pollAnswer.key; - if (pollAnswerIds[formattedMessageIndex]) { + if (defaultPoll && pollAnswerIds[formattedMessageIndex]) { label = intl.formatMessage(pollAnswerIds[formattedMessageIndex]); } diff --git a/bigbluebutton-html5/imports/ui/components/polling/container.jsx b/bigbluebutton-html5/imports/ui/components/polling/container.jsx index 7f2c9ce1c0..d9b8838b76 100644 --- a/bigbluebutton-html5/imports/ui/components/polling/container.jsx +++ b/bigbluebutton-html5/imports/ui/components/polling/container.jsx @@ -38,6 +38,7 @@ export default withTracker(() => { poll, pollAnswerIds: PollService.pollAnswerIds, pollTypes: PollService.pollTypes, + isDefaultPoll: PollService.isDefaultPoll, isMeteorConnected: Meteor.status().connected, }); })(PollingContainer); diff --git a/bigbluebutton-html5/imports/ui/components/presentation/presentation-toolbar/container.jsx b/bigbluebutton-html5/imports/ui/components/presentation/presentation-toolbar/container.jsx index cb15aec55c..9bd3030ef4 100755 --- a/bigbluebutton-html5/imports/ui/components/presentation/presentation-toolbar/container.jsx +++ b/bigbluebutton-html5/imports/ui/components/presentation/presentation-toolbar/container.jsx @@ -4,6 +4,7 @@ import { withTracker } from 'meteor/react-meteor-data'; import PresentationService from '/imports/ui/components/presentation/service'; import MediaService from '/imports/ui/components/media/service'; import Service from '/imports/ui/components/actions-bar/service'; +import PollService from '/imports/ui/components/poll/service'; import { makeCall } from '/imports/ui/services/api'; import PresentationToolbar from './component'; import PresentationToolbarService from './service'; @@ -39,7 +40,7 @@ export default withTracker((params) => { Session.set('forcePollOpen', true); window.dispatchEvent(new Event('panelChanged')); - makeCall('startPoll', type, id, '', answers); + makeCall('startPoll', PollService.pollTypes, type, id, '', answers); }; return { diff --git a/bigbluebutton-html5/imports/ui/components/whiteboard/annotations/poll/component.jsx b/bigbluebutton-html5/imports/ui/components/whiteboard/annotations/poll/component.jsx index 8a570a4974..56ff52db43 100644 --- a/bigbluebutton-html5/imports/ui/components/whiteboard/annotations/poll/component.jsx +++ b/bigbluebutton-html5/imports/ui/components/whiteboard/annotations/poll/component.jsx @@ -213,7 +213,7 @@ class PollDrawComponent extends Component { // if (!state.initialState) return; const { annotation } = this.props; - const { points, result } = annotation; + const { points, result, pollType } = annotation; const { slideWidth, slideHeight, intl } = this.props; // group duplicated responses and keep track of the number of removed items @@ -253,30 +253,14 @@ class PollDrawComponent extends Component { // adding value of the iterator to each line needed to create unique // keys while rendering at the end const arrayLength = reducedResult.length; + const { pollAnswerIds } = PollService; + const isDefaultPoll = PollService.isDefaultPoll(pollType); for (let i = 0; i < arrayLength; i += 1) { const _tempArray = []; const _result = reducedResult[i]; - let isDefaultPoll; - switch (_result.key.toLowerCase()) { - case 'true': - case 'false': - case 'yes': - case 'no': - case 'abstention': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - isDefaultPoll = true; - break; - default: - isDefaultPoll = false; - break; - } if (isDefaultPoll) { - _result.key = intl.formatMessage({ id: `app.poll.answer.${_result.key.toLowerCase()}` }); + _result.key = intl.formatMessage(pollAnswerIds[_result.key.toLowerCase()]); } if (_result.key.length > MAX_DISPLAYED_CHARS) { @@ -318,9 +302,8 @@ class PollDrawComponent extends Component { const maxLineHeight = (innerHeight * 0.75) / textArray.length; const lineToMeasure = textArray[0]; - const { pollAnswerIds } = PollService; const messageIndex = lineToMeasure[0].toLowerCase(); - if (pollAnswerIds[messageIndex]) { + if (isDefaultPoll && pollAnswerIds[messageIndex]) { lineToMeasure[0] = intl.formatMessage(pollAnswerIds[messageIndex]); } @@ -420,7 +403,8 @@ class PollDrawComponent extends Component { let label = textArray[i][0]; const formattedMessageIndex = label.toLowerCase(); - if (pollAnswerIds[formattedMessageIndex]) { + const isDefaultPoll = PollService.isDefaultPoll(annotation.pollType); + if (isDefaultPoll && pollAnswerIds[formattedMessageIndex]) { label = intl.formatMessage(pollAnswerIds[formattedMessageIndex]); } -- GitLab