bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/polling/service.js

52 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-04-26 21:47:44 +08:00
import { makeCall } from '/imports/ui/services/api';
import Polls from '/imports/api/polls';
2023-03-01 21:39:04 +08:00
import { debounce } from 'radash';
2016-05-06 02:50:18 +08:00
2019-04-02 12:07:45 +08:00
const MAX_CHAR_LENGTH = 5;
2021-02-05 00:54:50 +08:00
const handleVote = (pollId, answerIds) => {
makeCall('publishVote', pollId, answerIds);
};
const handleTypedVote = (pollId, answer) => {
makeCall('publishTypedVote', pollId, answer);
2021-02-09 14:22:41 +08:00
};
const mapPolls = () => {
2017-06-03 03:25:02 +08:00
const poll = Polls.findOne({});
2016-05-06 02:50:18 +08:00
if (!poll) {
return { pollExists: false };
}
const { answers } = poll;
let stackOptions = false;
answers.map((obj) => {
if (stackOptions) return obj;
2021-11-27 00:30:56 +08:00
if (obj.key && obj.key.length > MAX_CHAR_LENGTH) {
stackOptions = true;
}
return obj;
});
2017-07-25 20:26:45 +08:00
const amIRequester = poll.requester !== 'userId';
2016-05-06 02:50:18 +08:00
return {
poll: {
2017-07-25 20:26:45 +08:00
answers: poll.answers,
pollId: poll.id,
isMultipleResponse: poll.isMultipleResponse,
pollType: poll.pollType,
stackOptions,
question: poll.question,
secretPoll: poll.secretPoll,
2016-05-06 02:50:18 +08:00
},
pollExists: true,
2017-06-03 03:25:02 +08:00
amIRequester,
2023-03-01 21:39:04 +08:00
handleVote: debounce({ delay: 500 }, handleVote),
handleTypedVote: debounce({ delay: 500 }, handleTypedVote),
2016-05-06 02:50:18 +08:00
};
};
export default { mapPolls };