From 2d2968a92fe1649f86f7077aedb0b610d2bc1e47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20Souza?= Date: Tue, 9 Apr 2024 09:58:50 -0300 Subject: [PATCH] fix export usernames --- .../ui/components/user-list/service.js | 26 ++--------------- .../user-options-dropdown/component.tsx | 28 +++++++++++++++++-- .../user-options-dropdown/service.ts | 4 ++- .../imports/ui/core/graphql/queries/users.ts | 8 ++++++ 4 files changed, 38 insertions(+), 28 deletions(-) diff --git a/bigbluebutton-html5/imports/ui/components/user-list/service.js b/bigbluebutton-html5/imports/ui/components/user-list/service.js index c8958f0051..4ca94aa356 100755 --- a/bigbluebutton-html5/imports/ui/components/user-list/service.js +++ b/bigbluebutton-html5/imports/ui/components/user-list/service.js @@ -183,27 +183,6 @@ const addUserReaction = (users) => { }); }; -// TODO I think this method is no longer used, verify -const getUsers = () => { - let users = Users - .find({ - meetingId: Auth.meetingID, - }, userFindSorting) - .fetch(); - - const currentUser = Users.findOne({ userId: Auth.userID }, { fields: { role: 1, locked: 1 } }); - if (currentUser && currentUser.role === ROLE_VIEWER && currentUser.locked) { - const meeting = Meetings.findOne({ meetingId: Auth.meetingID }, - { fields: { 'lockSettings.hideUserList': 1 } }); - if (meeting && meeting.lockSettings && meeting.lockSettings.hideUserList) { - const moderatorOrCurrentUser = (u) => u.role === ROLE_MODERATOR || u.userId === Auth.userID; - users = users.filter(moderatorOrCurrentUser); - } - } - - return addIsSharingWebcam(addUserReaction(users)).sort(sortUsers); -}; - const formatUsers = (contextUsers, videoUsers, whiteboardUsers, reactionUsers) => { let users = contextUsers.filter((user) => user.loggedOut === false && user.left === false); @@ -598,9 +577,9 @@ const isUserPresenter = (userId = Auth.userID) => { return user ? user.presenter : false; }; -export const getUserNamesLink = (docTitle, fnSortedLabel, lnSortedLabel) => { +export const getUserNamesLink = (docTitle, fnSortedLabel, lnSortedLabel, users) => { const mimeType = 'text/plain'; - const userNamesObj = getUsers() + const userNamesObj = users .map((u) => { const name = u.name.split(' '); return ({ @@ -695,7 +674,6 @@ export default { sortUsersByName, sortUsers, toggleVoice, - getUsers, formatUsers, getActiveChats, getAvailableActions, diff --git a/bigbluebutton-html5/imports/ui/components/user-list/user-list-graphql/user-participants-title/user-options-dropdown/component.tsx b/bigbluebutton-html5/imports/ui/components/user-list/user-list-graphql/user-participants-title/user-options-dropdown/component.tsx index f1e388b8b2..cf3d5d715e 100644 --- a/bigbluebutton-html5/imports/ui/components/user-list/user-list-graphql/user-participants-title/user-options-dropdown/component.tsx +++ b/bigbluebutton-html5/imports/ui/components/user-list/user-list-graphql/user-participants-title/user-options-dropdown/component.tsx @@ -1,4 +1,9 @@ -import React, { useMemo, useRef, useState } from 'react'; +import React, { + useMemo, + useRef, + useState, + useEffect, +} from 'react'; import LockViewersContainer from '/imports/ui/components/lock-viewers/container'; import GuestPolicyContainer from '/imports/ui/components/waiting-users/guest-policy/container'; import CreateBreakoutRoomContainerGraphql from '../../../../breakout-room/breakout-room-graphql/create-breakout-room/component'; @@ -17,9 +22,10 @@ import { import { User } from '/imports/ui/Types/user'; import useCurrentUser from '/imports/ui/core/hooks/useCurrentUser'; import { isBreakoutRoomsEnabled, isLearningDashboardEnabled, isCaptionsEnabled } from '/imports/ui/services/features'; -import { useMutation } from '@apollo/client'; +import { useMutation, useLazyQuery } from '@apollo/client'; import { CLEAR_ALL_EMOJI } from '/imports/ui/core/graphql/mutations/userMutations'; import { SET_MUTED } from './mutations'; +import { GET_USER_NAMES } from '/imports/ui/core/graphql/queries/users'; import { notify } from '/imports/ui/services/notification'; import logger from '/imports/startup/client/logger'; @@ -183,6 +189,22 @@ const UserTitleOptions: React.FC = ({ const [clearAllEmoji] = useMutation(CLEAR_ALL_EMOJI); const [setMuted] = useMutation(SET_MUTED); + const [getUsers, { data: usersData, error: usersError }] = useLazyQuery(GET_USER_NAMES, { fetchPolicy: 'no-cache' }); + const users = usersData?.user || []; + + if (usersError) { + logger.error({ + logCode: 'user_options_get_users_error', + extraInfo: { usersError }, + }, 'Error fetching users names'); + } + + // users will only be fetched when getUsers is called + useEffect(() => { + if (users.length > 0) { + onSaveUserNames(intl, meetingName ?? '', users); + } + }, [users]); const toggleStatus = () => { clearAllEmoji(); @@ -264,7 +286,7 @@ const UserTitleOptions: React.FC = ({ allow: isModerator, key: uuids.current[4], label: intl.formatMessage(intlMessages.saveUserNames), - onClick: onSaveUserNames.bind(null, intl, meetingName ?? ''), + onClick: () => getUsers(), icon: 'download', dataTest: 'downloadUserNamesList', }, diff --git a/bigbluebutton-html5/imports/ui/components/user-list/user-list-graphql/user-participants-title/user-options-dropdown/service.ts b/bigbluebutton-html5/imports/ui/components/user-list/user-list-graphql/user-participants-title/user-options-dropdown/service.ts index bc07071b3a..7835006667 100644 --- a/bigbluebutton-html5/imports/ui/components/user-list/user-list-graphql/user-participants-title/user-options-dropdown/service.ts +++ b/bigbluebutton-html5/imports/ui/components/user-list/user-list-graphql/user-participants-title/user-options-dropdown/service.ts @@ -3,6 +3,7 @@ import { getUserNamesLink } from '/imports/ui/components/user-list/service'; import Settings from '/imports/ui/services/settings'; import LearningDashboardService from '/imports/ui/components/learning-dashboard/service'; import { defineMessages, IntlShape } from 'react-intl'; +import { User } from '/imports/ui/Types/user'; const intlMessages = defineMessages({ savedNamesListTitle: { @@ -19,7 +20,7 @@ const intlMessages = defineMessages({ }, }); -export const onSaveUserNames = (intl: IntlShape, meetingName: string) => { +export const onSaveUserNames = (intl: IntlShape, meetingName: string, users: [User]) => { // @ts-ignore - temporary while settings are still in .js const lang = Settings.application.locale; const date = new Date(); @@ -34,6 +35,7 @@ export const onSaveUserNames = (intl: IntlShape, meetingName: string) => { }), intl.formatMessage(intlMessages.sortedFirstNameHeading), intl.formatMessage(intlMessages.sortedLastNameHeading), + users, ).dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window })); }; diff --git a/bigbluebutton-html5/imports/ui/core/graphql/queries/users.ts b/bigbluebutton-html5/imports/ui/core/graphql/queries/users.ts index 51fdfaf510..350e169f58 100644 --- a/bigbluebutton-html5/imports/ui/core/graphql/queries/users.ts +++ b/bigbluebutton-html5/imports/ui/core/graphql/queries/users.ts @@ -78,3 +78,11 @@ export const GET_USER_IDS = gql` } } `; + +export const GET_USER_NAMES = gql` + query Users { + user { + name + } + } +`;