fix export usernames

This commit is contained in:
Ramón Souza 2024-04-09 09:58:50 -03:00
parent 43ca140b89
commit 2d2968a92f
4 changed files with 38 additions and 28 deletions

View File

@ -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) => { const formatUsers = (contextUsers, videoUsers, whiteboardUsers, reactionUsers) => {
let users = contextUsers.filter((user) => user.loggedOut === false && user.left === false); 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; return user ? user.presenter : false;
}; };
export const getUserNamesLink = (docTitle, fnSortedLabel, lnSortedLabel) => { export const getUserNamesLink = (docTitle, fnSortedLabel, lnSortedLabel, users) => {
const mimeType = 'text/plain'; const mimeType = 'text/plain';
const userNamesObj = getUsers() const userNamesObj = users
.map((u) => { .map((u) => {
const name = u.name.split(' '); const name = u.name.split(' ');
return ({ return ({
@ -695,7 +674,6 @@ export default {
sortUsersByName, sortUsersByName,
sortUsers, sortUsers,
toggleVoice, toggleVoice,
getUsers,
formatUsers, formatUsers,
getActiveChats, getActiveChats,
getAvailableActions, getAvailableActions,

View File

@ -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 LockViewersContainer from '/imports/ui/components/lock-viewers/container';
import GuestPolicyContainer from '/imports/ui/components/waiting-users/guest-policy/container'; import GuestPolicyContainer from '/imports/ui/components/waiting-users/guest-policy/container';
import CreateBreakoutRoomContainerGraphql from '../../../../breakout-room/breakout-room-graphql/create-breakout-room/component'; 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 { User } from '/imports/ui/Types/user';
import useCurrentUser from '/imports/ui/core/hooks/useCurrentUser'; import useCurrentUser from '/imports/ui/core/hooks/useCurrentUser';
import { isBreakoutRoomsEnabled, isLearningDashboardEnabled, isCaptionsEnabled } from '/imports/ui/services/features'; 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 { CLEAR_ALL_EMOJI } from '/imports/ui/core/graphql/mutations/userMutations';
import { SET_MUTED } from './mutations'; import { SET_MUTED } from './mutations';
import { GET_USER_NAMES } from '/imports/ui/core/graphql/queries/users';
import { notify } from '/imports/ui/services/notification'; import { notify } from '/imports/ui/services/notification';
import logger from '/imports/startup/client/logger'; import logger from '/imports/startup/client/logger';
@ -183,6 +189,22 @@ const UserTitleOptions: React.FC<UserTitleOptionsProps> = ({
const [clearAllEmoji] = useMutation(CLEAR_ALL_EMOJI); const [clearAllEmoji] = useMutation(CLEAR_ALL_EMOJI);
const [setMuted] = useMutation(SET_MUTED); 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 = () => { const toggleStatus = () => {
clearAllEmoji(); clearAllEmoji();
@ -264,7 +286,7 @@ const UserTitleOptions: React.FC<UserTitleOptionsProps> = ({
allow: isModerator, allow: isModerator,
key: uuids.current[4], key: uuids.current[4],
label: intl.formatMessage(intlMessages.saveUserNames), label: intl.formatMessage(intlMessages.saveUserNames),
onClick: onSaveUserNames.bind(null, intl, meetingName ?? ''), onClick: () => getUsers(),
icon: 'download', icon: 'download',
dataTest: 'downloadUserNamesList', dataTest: 'downloadUserNamesList',
}, },

View File

@ -3,6 +3,7 @@ import { getUserNamesLink } from '/imports/ui/components/user-list/service';
import Settings from '/imports/ui/services/settings'; import Settings from '/imports/ui/services/settings';
import LearningDashboardService from '/imports/ui/components/learning-dashboard/service'; import LearningDashboardService from '/imports/ui/components/learning-dashboard/service';
import { defineMessages, IntlShape } from 'react-intl'; import { defineMessages, IntlShape } from 'react-intl';
import { User } from '/imports/ui/Types/user';
const intlMessages = defineMessages({ const intlMessages = defineMessages({
savedNamesListTitle: { 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 // @ts-ignore - temporary while settings are still in .js
const lang = Settings.application.locale; const lang = Settings.application.locale;
const date = new Date(); const date = new Date();
@ -34,6 +35,7 @@ export const onSaveUserNames = (intl: IntlShape, meetingName: string) => {
}), }),
intl.formatMessage(intlMessages.sortedFirstNameHeading), intl.formatMessage(intlMessages.sortedFirstNameHeading),
intl.formatMessage(intlMessages.sortedLastNameHeading), intl.formatMessage(intlMessages.sortedLastNameHeading),
users,
).dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window })); ).dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window }));
}; };

View File

@ -78,3 +78,11 @@ export const GET_USER_IDS = gql`
} }
} }
`; `;
export const GET_USER_NAMES = gql`
query Users {
user {
name
}
}
`;