Skip to content

Commit

Permalink
Merge pull request #12561 from germanocaumo/answers-tarnslation-12546
Browse files Browse the repository at this point in the history
fix(poll): don't translate user/presenter typed answers
  • Loading branch information
antobinary committed Jun 12, 2021
2 parents ed1c08c + 7bedcb0 commit 062db71
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 38 deletions.
Expand Up @@ -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

Expand Down Expand Up @@ -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)
}
}

Expand Down
Expand Up @@ -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]])
Expand Down
Expand Up @@ -7,6 +7,7 @@ export default function userVoted({ body }, meetingId) {
check(meetingId, String);
check(poll, {
id: String,
questionType: String,
questionText: String,
answers: [
{
Expand Down
Expand Up @@ -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';
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions bigbluebutton-html5/imports/ui/components/poll/component.jsx
Expand Up @@ -351,6 +351,7 @@ class Poll extends Component {
currentPoll,
pollAnswerIds,
usernames,
isDefaultPoll,
} = this.props;

return (
Expand All @@ -365,6 +366,7 @@ class Poll extends Component {
currentPoll,
pollAnswerIds,
usernames,
isDefaultPoll,
}}
handleBackClick={this.handleBackClick}
/>
Expand Down
6 changes: 4 additions & 2 deletions bigbluebutton-html5/imports/ui/components/poll/container.jsx
Expand Up @@ -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');

Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion bigbluebutton-html5/imports/ui/components/poll/service.js
Expand Up @@ -23,7 +23,7 @@ const pollTypes = {
A3: 'A-3',
A4: 'A-4',
A5: 'A-5',
Custom: 'custom',
Custom: 'CUSTOM',
Response: 'R-',
}

Expand Down
Expand Up @@ -92,7 +92,8 @@ class Polling extends Component {
handleVote,
handleTypedVote,
pollAnswerIds,
pollTypes
pollTypes,
isDefaultPoll,
} = this.props;

const {
Expand All @@ -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,
Expand Down Expand Up @@ -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]);
}

Expand Down
Expand Up @@ -38,6 +38,7 @@ export default withTracker(() => {
poll,
pollAnswerIds: PollService.pollAnswerIds,
pollTypes: PollService.pollTypes,
isDefaultPoll: PollService.isDefaultPoll,
isMeteorConnected: Meteor.status().connected,
});
})(PollingContainer);
Expand Up @@ -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';
Expand Down Expand Up @@ -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 {
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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]);
}

Expand Down Expand Up @@ -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]);
}

Expand Down

0 comments on commit 062db71

Please sign in to comment.