From 0ef2e8afeaf7bc775f775620cf9aeafe8fa68d10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20Souza?= Date: Fri, 8 Dec 2023 15:51:41 -0300 Subject: [PATCH] migrate publishTypedVote meteor call --- .../imports/api/polls/server/methods.js | 2 - .../polls/server/methods/publishTypedVote.js | 79 ------------------- .../imports/ui/components/poll/mutations.jsx | 13 ++- .../ui/components/polling/container.jsx | 18 ++++- .../imports/ui/components/polling/service.js | 5 -- 5 files changed, 27 insertions(+), 90 deletions(-) delete mode 100644 bigbluebutton-html5/imports/api/polls/server/methods/publishTypedVote.js diff --git a/bigbluebutton-html5/imports/api/polls/server/methods.js b/bigbluebutton-html5/imports/api/polls/server/methods.js index 4e8c9f442a..12a28e83f3 100644 --- a/bigbluebutton-html5/imports/api/polls/server/methods.js +++ b/bigbluebutton-html5/imports/api/polls/server/methods.js @@ -1,12 +1,10 @@ import { Meteor } from 'meteor/meteor'; -import publishTypedVote from './methods/publishTypedVote'; import publishVote from './methods/publishVote'; import startPoll from './methods/startPoll'; import stopPoll from './methods/stopPoll'; Meteor.methods({ publishVote, - publishTypedVote, startPoll, stopPoll, }); diff --git a/bigbluebutton-html5/imports/api/polls/server/methods/publishTypedVote.js b/bigbluebutton-html5/imports/api/polls/server/methods/publishTypedVote.js deleted file mode 100644 index b2e10e0bf9..0000000000 --- a/bigbluebutton-html5/imports/api/polls/server/methods/publishTypedVote.js +++ /dev/null @@ -1,79 +0,0 @@ -import RedisPubSub from '/imports/startup/server/redis'; -import { check } from 'meteor/check'; -import Polls from '/imports/api/polls'; -import { extractCredentials } from '/imports/api/common/server/helpers'; -import Logger from '/imports/startup/server/logger'; - -export default async function publishTypedVote(id, pollAnswer) { - const REDIS_CONFIG = Meteor.settings.private.redis; - const CHANNEL = REDIS_CONFIG.channels.toAkkaApps; - const MAX_INPUT_CHARS = Meteor.settings.public.poll.maxTypedAnswerLength; - let EVENT_NAME = 'RespondToTypedPollReqMsg'; - - try { - const { meetingId, requesterUserId } = extractCredentials(this.userId); - - check(meetingId, String); - check(requesterUserId, String); - check(pollAnswer, String); - check(id, String); - - const allowedToVote = await Polls.findOneAsync({ - id, - users: { $in: [requesterUserId] }, - meetingId, - }, { - fields: { - users: 1, - }, - }); - - if (!allowedToVote) { - Logger.info(`Poll User={${requesterUserId}} has already voted in PollId={${id}}`); - return null; - } - - const activePoll = await Polls.findOneAsync({ meetingId, id }, { - fields: { - answers: 1, - }, - }); - - let existingAnsId = null; - activePoll.answers.forEach((a) => { - if (a.key === pollAnswer) existingAnsId = a.id; - }); - - if (existingAnsId !== null) { - check(existingAnsId, Number); - EVENT_NAME = 'RespondToPollReqMsg'; - - return RedisPubSub.publishUserMessage( - CHANNEL, - EVENT_NAME, - meetingId, - requesterUserId, - { - requesterId: requesterUserId, - pollId: id, - questionId: 0, - answerIds: [existingAnsId], - }, - ); - } - - const payload = { - requesterId: requesterUserId, - pollId: id, - questionId: 0, - answer: pollAnswer.substring(0, MAX_INPUT_CHARS), - }; - - return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload); - } catch (err) { - Logger.error(`Exception while invoking method publishTypedVote ${err.stack}`); - } - //In this case we return true because - //lint asks for async functions to return some value. - return true; -} diff --git a/bigbluebutton-html5/imports/ui/components/poll/mutations.jsx b/bigbluebutton-html5/imports/ui/components/poll/mutations.jsx index 9fabbede0e..a471be37de 100644 --- a/bigbluebutton-html5/imports/ui/components/poll/mutations.jsx +++ b/bigbluebutton-html5/imports/ui/components/poll/mutations.jsx @@ -5,8 +5,19 @@ export const POLL_PUBLISH_RESULT = gql` pollPublishResult( pollId: $pollId, ) - }`; + } +`; + +export const POLL_SUBMIT_TYPED_VOTE = gql` + mutation PollSubmitTypedVote($pollId: String!, $answer: String!) { + pollSubmitUserTypedVote( + pollId: $pollId, + answer: $answer, + ) + } +`; export default { POLL_PUBLISH_RESULT, + POLL_SUBMIT_TYPED_VOTE, }; diff --git a/bigbluebutton-html5/imports/ui/components/polling/container.jsx b/bigbluebutton-html5/imports/ui/components/polling/container.jsx index 4e1f7aa2bd..2732596ccb 100644 --- a/bigbluebutton-html5/imports/ui/components/polling/container.jsx +++ b/bigbluebutton-html5/imports/ui/components/polling/container.jsx @@ -1,11 +1,13 @@ import React from 'react'; import PropTypes from 'prop-types'; import { withTracker } from 'meteor/react-meteor-data'; +import { useMutation } from '@apollo/client'; import PollingService from './service'; import PollService from '/imports/ui/components/poll/service'; import PollingComponent from './component'; import { isPollingEnabled } from '/imports/ui/services/features'; import useCurrentUser from '/imports/ui/core/hooks/useCurrentUser'; +import { POLL_SUBMIT_TYPED_VOTE } from '/imports/ui/components/poll/mutations'; const propTypes = { pollExists: PropTypes.bool.isRequired, @@ -17,9 +19,20 @@ const PollingContainer = ({ pollExists, ...props }) => { })); const showPolling = pollExists && !currentUserData?.presenter && isPollingEnabled(); + const [pollSubmitUserTypedVote] = useMutation(POLL_SUBMIT_TYPED_VOTE); + + const handleTypedVote = (pollId, answer) => { + pollSubmitUserTypedVote({ + variables: { + pollId, + answer, + }, + }); + }; + if (showPolling) { return ( - + ); } return null; @@ -29,7 +42,7 @@ PollingContainer.propTypes = propTypes; export default withTracker(() => { const { - pollExists, handleVote, poll, handleTypedVote, + pollExists, handleVote, poll, } = PollingService.mapPolls(); const { pollTypes } = PollService; @@ -41,7 +54,6 @@ export default withTracker(() => { return ({ pollExists, handleVote, - handleTypedVote, poll, pollAnswerIds: PollService.pollAnswerIds, pollTypes, diff --git a/bigbluebutton-html5/imports/ui/components/polling/service.js b/bigbluebutton-html5/imports/ui/components/polling/service.js index b2a2388246..2f4b3801d2 100644 --- a/bigbluebutton-html5/imports/ui/components/polling/service.js +++ b/bigbluebutton-html5/imports/ui/components/polling/service.js @@ -8,10 +8,6 @@ const handleVote = (pollId, answerIds) => { makeCall('publishVote', pollId, answerIds); }; -const handleTypedVote = (pollId, answer) => { - makeCall('publishTypedVote', pollId, answer); -}; - const mapPolls = () => { const poll = Polls.findOne({}); if (!poll) { @@ -44,7 +40,6 @@ const mapPolls = () => { pollExists: true, amIRequester, handleVote: debounce(handleVote, 500, { leading: true, trailing: false }), - handleTypedVote: debounce(handleTypedVote, 500, { leading: true, trailing: false }), }; };