diff --git a/bigbluebutton-html5/imports/api/polls/server/handlers/sendPollChatMsg.js b/bigbluebutton-html5/imports/api/polls/server/handlers/sendPollChatMsg.js index 34101bf31fc7d6c0491b078776409e2ece591fb6..8870fdb41df6080061ea74cb51db8ae71d433d2e 100644 --- a/bigbluebutton-html5/imports/api/polls/server/handlers/sendPollChatMsg.js +++ b/bigbluebutton-html5/imports/api/polls/server/handlers/sendPollChatMsg.js @@ -11,12 +11,27 @@ export default function sendPollChatMsg({ body }, meetingId) { const { answers, numRespondents } = poll; + const caseInsensitiveReducer = (acc, item) => { + const index = acc.findIndex(ans => ans.key.toLowerCase() === item.key.toLowerCase()); + if(index !== -1) { + if(acc[index].numVotes >= item.numVotes) acc[index].numVotes += item.numVotes; + else { + const tempVotes = acc[index].numVotes; + acc[index] = item; + acc[index].numVotes += tempVotes; + } + } else { + acc.push(item); + } + return acc; + }; + let responded = 0; let resultString = 'bbb-published-poll-\n'; answers.map((item) => { responded += item.numVotes; return item; - }).map((item) => { + }).reduce(caseInsensitiveReducer, []).map((item) => { item.key = item.key.split('<br/>').join('<br#>'); const numResponded = responded === numRespondents ? numRespondents : responded; const pct = Math.round(item.numVotes / numResponded * 100); 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 2a2a8b86f5c220acdb61207d29fd4c11db011193..1cb4361655c89c90f21ae9a3ec4ca7cf8b15d74d 100644 --- a/bigbluebutton-html5/imports/ui/components/poll/live-result/component.jsx +++ b/bigbluebutton-html5/imports/ui/components/poll/live-result/component.jsx @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'; import _ from 'lodash'; import { defineMessages, injectIntl } from 'react-intl'; import Button from '/imports/ui/components/button/component'; +import caseInsensitiveReducer from '/imports/utils/caseInsensitiveReducer'; import { styles } from './styles'; import Service from './service'; @@ -94,7 +95,7 @@ class LiveResult extends PureComponent { const pollStats = []; - answers.map((obj) => { + answers.reduce(caseInsensitiveReducer, []).map((obj) => { const formattedMessageIndex = obj.key.toLowerCase(); const pct = Math.round(obj.numVotes / numRespondents * 100); const pctFotmatted = `${Number.isNaN(pct) ? 0 : pct}%`; 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 43deed4899a39521686c42f54acb1e0517171be7..2da8142e46586507e6d552c0ebce9b9d65ed58db 100644 --- a/bigbluebutton-html5/imports/ui/components/whiteboard/annotations/poll/component.jsx +++ b/bigbluebutton-html5/imports/ui/components/whiteboard/annotations/poll/component.jsx @@ -1,6 +1,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import PollService from '/imports/ui/components/poll/service'; +import caseInsensitiveReducer from '/imports/utils/caseInsensitiveReducer'; import { injectIntl, defineMessages } from 'react-intl'; import styles from './styles'; import { prototype } from 'clipboard'; @@ -230,9 +231,10 @@ class PollDrawComponent extends Component { let votesTotal = 0; let maxNumVotes = 0; const textArray = []; + const reducedResult = result.reduce(caseInsensitiveReducer, []); // counting the total number of votes, finding the biggest number of votes - result.reduce((previousValue, currentValue) => { + reducedResult.reduce((previousValue, currentValue) => { votesTotal = previousValue + currentValue.numVotes; if (maxNumVotes < currentValue.numVotes) { maxNumVotes = currentValue.numVotes; @@ -244,10 +246,10 @@ class PollDrawComponent extends Component { // filling the textArray with data to display // adding value of the iterator to each line needed to create unique // keys while rendering at the end - const arrayLength = result.length; + const arrayLength = reducedResult.length; for (let i = 0; i < arrayLength; i += 1) { const _tempArray = []; - const _result = result[i]; + const _result = reducedResult[i]; let isDefaultPoll; switch (_result.key.toLowerCase()) { case 'true': diff --git a/bigbluebutton-html5/imports/utils/caseInsensitiveReducer.js b/bigbluebutton-html5/imports/utils/caseInsensitiveReducer.js new file mode 100644 index 0000000000000000000000000000000000000000..f8cd942d472b22829e51ac68743fe96cfe451f68 --- /dev/null +++ b/bigbluebutton-html5/imports/utils/caseInsensitiveReducer.js @@ -0,0 +1,17 @@ +const caseInsensitiveReducer = (acc, item) => { + const index = acc.findIndex(ans => ans.key.toLowerCase() === item.key.toLowerCase()); + if(index !== -1) { + if(acc[index].numVotes >= item.numVotes) acc[index].numVotes += item.numVotes; + else { + const tempVotes = acc[index].numVotes; + acc[index] = item; + acc[index].numVotes += tempVotes; + } + } else { + acc.push(item); + } + return acc; +}; + +export default caseInsensitiveReducer; + \ No newline at end of file