From a20ee430ed326a8ce055bac7511c146098afcbfa Mon Sep 17 00:00:00 2001 From: Bohdan Zhemelinskyi Date: Wed, 3 Nov 2021 18:51:32 +0000 Subject: [PATCH] Improvements based on sonar cloud feedback --- .../server/modifiers/updateRandomViewer.js | 37 ++++++++++--------- .../modal/random-user/container.jsx | 18 ++++++--- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/bigbluebutton-html5/imports/api/meetings/server/modifiers/updateRandomViewer.js b/bigbluebutton-html5/imports/api/meetings/server/modifiers/updateRandomViewer.js index 0f5bcc9dd3..1c74e037d9 100644 --- a/bigbluebutton-html5/imports/api/meetings/server/modifiers/updateRandomViewer.js +++ b/bigbluebutton-html5/imports/api/meetings/server/modifiers/updateRandomViewer.js @@ -79,23 +79,8 @@ export default function updateRandomUser(meetingId, userIds, choice, requesterId } else { // We generate 5 users randomly, just for animation, and last one is the chosen one - const itrations = intervals.length -1; - let IDs = userIds.slice(); - for(i = 0; i < itrations; i++ ){ - if(IDs == 0) { // we used up all the options - IDs = userIds.slice(); //start over - let userId = IDs.splice(0, 1); - if(userList[userList.length] == [userId, intervals[i]]){ //If we start over with the one we finnished, change it - IDs.push(userId); - userId = IDs.splice(0, 1) - } - userList.push([userId, intervals[i]]); - } else { - const userId = IDs.splice(Math.floor(Math.random() * IDs.length), 1); - userList.push([userId, intervals[i]]); - } - } - userList.push([chosenUser, intervals[itrations + 1]]); + getFiveRandom(userList, userIds); + userList.push([chosenUser, intervals[intervals.length]]); } const modifier = { @@ -113,3 +98,21 @@ export default function updateRandomUser(meetingId, userIds, choice, requesterId Logger.error(`Setting randomly selected userId and interval = ${userList} by requesterId=${requesterId} in meetingId=${meetingId}`); } } + +function getFiveRandom(userList, userIds){ + let IDs = userIds.slice(); + for(let i = 0; i < intervals.length - 1; i++ ){ + if(IDs == 0) { // we used up all the options + IDs = userIds.slice(); //start over + let userId = IDs.splice(0, 1); + if(userList[userList.length] == [userId, intervals[i]]){ //If we start over with the one we finnished, change it + IDs.push(userId); + userId = IDs.splice(0, 1) + } + userList.push([userId, intervals[i]]); + } else { + const userId = IDs.splice(Math.floor(Math.random() * IDs.length), 1); + userList.push([userId, intervals[i]]); + } + } +} diff --git a/bigbluebutton-html5/imports/ui/components/modal/random-user/container.jsx b/bigbluebutton-html5/imports/ui/components/modal/random-user/container.jsx index 6394583a26..e4e140aa1e 100644 --- a/bigbluebutton-html5/imports/ui/components/modal/random-user/container.jsx +++ b/bigbluebutton-html5/imports/ui/components/modal/random-user/container.jsx @@ -28,12 +28,20 @@ const RandomUserSelectContainer = (props) => { const currentUser = { userId: Auth.userID, presenter: users[Auth.meetingID][Auth.userID].presenter }; - if(!currentUser.presenter && //this functionality does not bother presenter - (keepModalOpen == false) && //we only ween a change if modal has been closed before - (randomlySelectedUser[0][1] != updateIndicator)//if tey are different, a user was generated - ){ keepModalOpen = true; } //reopen modal + try{ + if(!currentUser.presenter && //this functionality does not bother presenter + (!keepModalOpen) && //we only ween a change if modal has been closed before + (randomlySelectedUser[0][1] != updateIndicator)//if tey are different, a user was generated + ){ keepModalOpen = true; } //reopen modal - if(!currentUser.presenter){ updateIndicator = randomlySelectedUser[0][1]; } //keep indicator up to date + if(!currentUser.presenter){ updateIndicator = randomlySelectedUser[0][1]; } //keep indicator up to date + }catch(err){ + console.error( + "Issue in Random User container caused by back-end crash\n" + + "Value of 6 randomly selected users was passed as {" + + randomlySelectedUser + + "}\nHowever, it is handled."); + } if (randomlySelectedUser) { mappedRandomlySelectedUsers = randomlySelectedUser.map((ui) => {