Merge pull request #19406 from ramonlsouza/migrate-guest-actions
refactor: migrate guestUsers actions
This commit is contained in:
commit
5bf01fdbf8
@ -1,9 +0,0 @@
|
||||
import { Mongo } from 'meteor/mongo';
|
||||
|
||||
const collectionOptions = Meteor.isClient ? {
|
||||
connection: null,
|
||||
} : {};
|
||||
|
||||
const GuestUsers = new Mongo.Collection('guestUsers', collectionOptions);
|
||||
|
||||
export default GuestUsers;
|
@ -1 +0,0 @@
|
||||
import './methods';
|
@ -1,12 +0,0 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import allowPendingUsers from '/imports/api/guest-users/server/methods/allowPendingUsers';
|
||||
import changeGuestPolicy from '/imports/api/guest-users/server/methods/changeGuestPolicy';
|
||||
import setGuestLobbyMessage from '/imports/api/guest-users/server/methods/setGuestLobbyMessage';
|
||||
import setPrivateGuestLobbyMessage from '/imports/api/guest-users/server/methods/setPrivateGuestLobbyMessage';
|
||||
|
||||
Meteor.methods({
|
||||
allowPendingUsers,
|
||||
changeGuestPolicy,
|
||||
setGuestLobbyMessage,
|
||||
setPrivateGuestLobbyMessage,
|
||||
});
|
@ -1,31 +0,0 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { check } from 'meteor/check';
|
||||
import RedisPubSub from '/imports/startup/server/redis';
|
||||
import Logger from '/imports/startup/server/logger';
|
||||
import { extractCredentials } from '/imports/api/common/server/helpers';
|
||||
|
||||
const REDIS_CONFIG = Meteor.settings.private.redis;
|
||||
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
||||
const EVENT_NAME = 'GuestsWaitingApprovedMsg';
|
||||
|
||||
export default function allowPendingUsers(guests, status) {
|
||||
try {
|
||||
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
||||
|
||||
check(meetingId, String);
|
||||
check(requesterUserId, String);
|
||||
check(guests, Array);
|
||||
const mappedGuests = guests.map((guest) => ({ status, guest: guest.userId }));
|
||||
|
||||
const payload = {
|
||||
approvedBy: requesterUserId,
|
||||
guests: mappedGuests,
|
||||
};
|
||||
|
||||
Logger.info(`User=${requesterUserId} ${status} guests ${JSON.stringify(mappedGuests)}`);
|
||||
|
||||
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
|
||||
} catch (err) {
|
||||
Logger.error(`Exception while invoking method allowPendingUsers ${err.stack}`);
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { check } from 'meteor/check';
|
||||
import RedisPubSub from '/imports/startup/server/redis';
|
||||
import Logger from '/imports/startup/server/logger';
|
||||
import { extractCredentials } from '/imports/api/common/server/helpers';
|
||||
|
||||
const REDIS_CONFIG = Meteor.settings.private.redis;
|
||||
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
||||
const EVENT_NAME = 'SetGuestPolicyCmdMsg';
|
||||
|
||||
export default function changeGuestPolicy(policyRule) {
|
||||
try {
|
||||
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
||||
|
||||
check(meetingId, String);
|
||||
check(requesterUserId, String);
|
||||
check(policyRule, String);
|
||||
|
||||
const payload = {
|
||||
setBy: requesterUserId,
|
||||
policy: policyRule,
|
||||
};
|
||||
|
||||
Logger.info(`User=${requesterUserId} change guest policy to ${policyRule}`);
|
||||
|
||||
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
|
||||
} catch (err) {
|
||||
Logger.error(`Exception while invoking method changeGuestPolicy ${err.stack}`);
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { check } from 'meteor/check';
|
||||
import RedisPubSub from '/imports/startup/server/redis';
|
||||
import Logger from '/imports/startup/server/logger';
|
||||
import { extractCredentials, parseMessage } from '/imports/api/common/server/helpers';
|
||||
|
||||
const REDIS_CONFIG = Meteor.settings.private.redis;
|
||||
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
||||
const EVENT_NAME = 'SetGuestLobbyMessageCmdMsg';
|
||||
|
||||
export default function setGuestLobbyMessage(message) {
|
||||
try {
|
||||
check(message, String);
|
||||
|
||||
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
||||
|
||||
check(meetingId, String);
|
||||
check(requesterUserId, String);
|
||||
const payload = { message: parseMessage(message) };
|
||||
|
||||
Logger.info(`User=${requesterUserId} set guest lobby message to ${message}`);
|
||||
|
||||
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
|
||||
} catch (err) {
|
||||
Logger.error(`Exception while invoking method setGuestLobbyMessage ${err.stack}`);
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { check } from 'meteor/check';
|
||||
import RedisPubSub from '/imports/startup/server/redis';
|
||||
import Logger from '/imports/startup/server/logger';
|
||||
import { extractCredentials, parseMessage } from '/imports/api/common/server/helpers';
|
||||
|
||||
|
||||
const REDIS_CONFIG = Meteor.settings.private.redis;
|
||||
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
||||
const EVENT_NAME = 'SetPrivateGuestLobbyMessageCmdMsg';
|
||||
|
||||
export default function setPrivateGuestLobbyMessage(message, guestId) {
|
||||
check(message, String);
|
||||
check(guestId, String);
|
||||
|
||||
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
||||
|
||||
check(meetingId, String);
|
||||
check(requesterUserId, String);
|
||||
|
||||
const payload = { guestId, message: parseMessage(message) };
|
||||
|
||||
Logger.info(`User=${requesterUserId} sent a private guest lobby message to guest user=${guestId}`);
|
||||
|
||||
return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
|
||||
}
|
||||
|
@ -1,8 +1,10 @@
|
||||
import React from 'react';
|
||||
import { withTracker } from 'meteor/react-meteor-data';
|
||||
import { useMutation } from '@apollo/client';
|
||||
import GuestPolicyComponent from './component';
|
||||
import Service from '../service';
|
||||
import useCurrentUser from '/imports/ui/core/hooks/useCurrentUser';
|
||||
import { SET_POLICY } from '../mutations';
|
||||
|
||||
const GuestPolicyContainer = (props) => {
|
||||
const { data: currentUserData } = useCurrentUser((user) => ({
|
||||
@ -10,10 +12,19 @@ const GuestPolicyContainer = (props) => {
|
||||
}));
|
||||
const amIModerator = currentUserData?.isModerator;
|
||||
|
||||
return amIModerator && <GuestPolicyComponent {...props} />;
|
||||
const [setPolicy] = useMutation(SET_POLICY);
|
||||
|
||||
const changeGuestPolicy = (guestPolicy) => {
|
||||
setPolicy({
|
||||
variables: {
|
||||
guestPolicy,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return amIModerator && <GuestPolicyComponent changeGuestPolicy={changeGuestPolicy} {...props} />;
|
||||
};
|
||||
|
||||
export default withTracker(() => ({
|
||||
guestPolicy: Service.getGuestPolicy(),
|
||||
changeGuestPolicy: Service.changeGuestPolicy,
|
||||
}))(GuestPolicyContainer);
|
||||
|
@ -0,0 +1,46 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export interface GuestUserApprovalStatus {
|
||||
guest: string;
|
||||
status: string;
|
||||
}
|
||||
|
||||
export const SET_POLICY = gql`
|
||||
mutation SetPolicy($guestPolicy: String!) {
|
||||
guestUsersSetPolicy(
|
||||
guestPolicy: $guestPolicy,
|
||||
)
|
||||
}
|
||||
`;
|
||||
|
||||
export const SUBMIT_APPROVAL_STATUS = gql`
|
||||
mutation SubmitApprovalStatus($guests: [GuestUserApprovalStatus]!) {
|
||||
guestUsersSubmitApprovalStatus(
|
||||
guests: $guests,
|
||||
)
|
||||
}
|
||||
`;
|
||||
|
||||
export const SET_LOBBY_MESSAGE = gql`
|
||||
mutation SetLobbyMessage($message: String!) {
|
||||
guestUsersSetLobbyMessage(
|
||||
message: $message,
|
||||
)
|
||||
}
|
||||
`;
|
||||
|
||||
export const SET_LOBBY_MESSAGE_PRIVATE = gql`
|
||||
mutation SetLobbyMessage($guestId: String!, $message: String!) {
|
||||
guestUsersSetLobbyMessagePrivate(
|
||||
guestId: $guestId,
|
||||
message: $message,
|
||||
)
|
||||
}
|
||||
`;
|
||||
|
||||
export default {
|
||||
SET_POLICY,
|
||||
SUBMIT_APPROVAL_STATUS,
|
||||
SET_LOBBY_MESSAGE,
|
||||
SET_LOBBY_MESSAGE_PRIVATE,
|
||||
};
|
@ -1,10 +1,5 @@
|
||||
import Meetings from '/imports/api/meetings';
|
||||
import Auth from '/imports/ui/services/auth';
|
||||
import { makeCall } from '/imports/ui/services/api';
|
||||
|
||||
const guestUsersCall = (guestsArray, status) => makeCall('allowPendingUsers', guestsArray, status);
|
||||
|
||||
const changeGuestPolicy = (policyRule) => makeCall('changeGuestPolicy', policyRule);
|
||||
|
||||
const getGuestPolicy = () => {
|
||||
const meeting = Meetings.findOne(
|
||||
@ -33,28 +28,20 @@ const getGuestLobbyMessage = () => {
|
||||
return '';
|
||||
};
|
||||
|
||||
const setGuestLobbyMessage = (message) => makeCall('setGuestLobbyMessage', message);
|
||||
|
||||
const setPrivateGuestLobbyMessage = (message, guestId) => makeCall('setPrivateGuestLobbyMessage', message, guestId);
|
||||
|
||||
const privateMessageVisible = (id) => {
|
||||
const privateInputSpace = document.getElementById(id);
|
||||
if (privateInputSpace.style.display === "block") {
|
||||
privateInputSpace.style.display = "none";
|
||||
if (privateInputSpace.style.display === 'block') {
|
||||
privateInputSpace.style.display = 'none';
|
||||
} else {
|
||||
privateInputSpace.style.display = "block";
|
||||
privateInputSpace.style.display = 'block';
|
||||
}
|
||||
};
|
||||
|
||||
export default {
|
||||
guestUsersCall,
|
||||
privateMessageVisible,
|
||||
changeGuestPolicy,
|
||||
getGuestPolicy,
|
||||
isWaitingRoomEnabled,
|
||||
isGuestLobbyMessageEnabled,
|
||||
getGuestLobbyMessage,
|
||||
setGuestLobbyMessage,
|
||||
setPrivateGuestLobbyMessage,
|
||||
allowRememberChoice,
|
||||
};
|
||||
|
@ -4,7 +4,7 @@ import React, {
|
||||
useMemo,
|
||||
useState,
|
||||
} from 'react';
|
||||
import { useSubscription } from '@apollo/client';
|
||||
import { useSubscription, useMutation } from '@apollo/client';
|
||||
import { defineMessages, useIntl } from 'react-intl';
|
||||
import { useMeeting } from '/imports/ui/core/hooks/useMeeting';
|
||||
import { notify } from '/imports/ui/services/notification';
|
||||
@ -18,11 +18,7 @@ import { layoutDispatch } from '../../layout/context';
|
||||
import { ACTIONS, PANELS } from '../../layout/enums';
|
||||
import Styled from './styles';
|
||||
import {
|
||||
guestUsersCall,
|
||||
privateMessageVisible,
|
||||
setGuestLobbyMessage,
|
||||
setPrivateGuestLobbyMessage,
|
||||
changeGuestPolicy,
|
||||
} from './service';
|
||||
import browserInfo from '/imports/utils/browserInfo';
|
||||
import Header from '/imports/ui/components/common/control-header/component';
|
||||
@ -30,6 +26,12 @@ import TextInput from '/imports/ui/components/text-input/component';
|
||||
import renderNoUserWaitingItem from './guest-items/noPendingGuestUser';
|
||||
import renderPendingUsers from './guest-items/guestPendingUser';
|
||||
import logger from '/imports/startup/client/logger';
|
||||
import {
|
||||
SET_POLICY,
|
||||
SUBMIT_APPROVAL_STATUS,
|
||||
SET_LOBBY_MESSAGE,
|
||||
SET_LOBBY_MESSAGE_PRIVATE,
|
||||
} from '../mutations';
|
||||
|
||||
// @ts-ignore - temporary, while meteor exists in the project
|
||||
const isGuestLobbyMessageEnabled = Meteor.settings.public.app.enableGuestLobbyMessage;
|
||||
@ -166,6 +168,40 @@ const GuestUsersManagementPanel: React.FC<GuestUsersManagementPanelProps> = ({
|
||||
const intl = useIntl();
|
||||
const { isChrome } = browserInfo;
|
||||
const [rememberChoice, setRememberChoice] = useState(false);
|
||||
const [setPolicy] = useMutation(SET_POLICY);
|
||||
const [submitApprovalStatus] = useMutation(SUBMIT_APPROVAL_STATUS);
|
||||
const [setLobbyMessage] = useMutation(SET_LOBBY_MESSAGE);
|
||||
const [setLobbyMessagePrivate] = useMutation(SET_LOBBY_MESSAGE_PRIVATE);
|
||||
|
||||
const guestUsersCall = useCallback((users: GuestWaitingUser[], status: string) => {
|
||||
const guests = users.map((user) => ({
|
||||
guest: user.user.userId,
|
||||
status,
|
||||
}));
|
||||
|
||||
submitApprovalStatus({
|
||||
variables: {
|
||||
guests,
|
||||
},
|
||||
});
|
||||
}, []);
|
||||
|
||||
const setGuestLobbyMessage = useCallback((message: string) => {
|
||||
setLobbyMessage({
|
||||
variables: {
|
||||
message,
|
||||
},
|
||||
});
|
||||
}, []);
|
||||
|
||||
const setPrivateGuestLobbyMessage = useCallback((message: string, guestId: string) => {
|
||||
setLobbyMessagePrivate({
|
||||
variables: {
|
||||
guestId,
|
||||
message,
|
||||
},
|
||||
});
|
||||
}, []);
|
||||
|
||||
const existPendingUsers = authedGuestUsers.length > 0 || unauthedGuestUsers.length > 0;
|
||||
|
||||
@ -200,7 +236,11 @@ const GuestUsersManagementPanel: React.FC<GuestUsersManagementPanelProps> = ({
|
||||
message: string,
|
||||
) => () => {
|
||||
if (shouldExecutePolicy) {
|
||||
changeGuestPolicy(policyRule);
|
||||
setPolicy({
|
||||
variables: {
|
||||
guestPolicy: policyRule,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
closePanel();
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { GuestWaitingUser } from './queries';
|
||||
import { makeCall } from '/imports/ui/services/api';
|
||||
|
||||
export const privateMessageVisible = (id: string) => {
|
||||
@ -18,18 +17,9 @@ export const getNameInitials = (name: string) => {
|
||||
return nameInitials.replace(/^\w/, (c: string) => c.toUpperCase());
|
||||
};
|
||||
|
||||
export const guestUsersCall = (guestsArray: GuestWaitingUser[], status: string) => makeCall('allowPendingUsers', guestsArray, status);
|
||||
|
||||
export const setGuestLobbyMessage = (message: string) => makeCall('setGuestLobbyMessage', message);
|
||||
|
||||
export const setPrivateGuestLobbyMessage = (message: string, guestId: string) => makeCall('setPrivateGuestLobbyMessage', message, guestId);
|
||||
|
||||
export const changeGuestPolicy = (policyRule: string) => makeCall('changeGuestPolicy', policyRule);
|
||||
|
||||
export default {
|
||||
privateMessageVisible,
|
||||
guestUsersCall,
|
||||
setGuestLobbyMessage,
|
||||
getNameInitials,
|
||||
changeGuestPolicy,
|
||||
};
|
||||
|
@ -24,7 +24,6 @@ import '/imports/api/timer/server';
|
||||
import '/imports/api/audio-captions/server';
|
||||
import '/imports/api/external-videos/server';
|
||||
import '/imports/api/pads/server';
|
||||
import '/imports/api/guest-users/server';
|
||||
import '/imports/api/local-settings/server';
|
||||
import '/imports/api/voice-call-states/server';
|
||||
import '/imports/api/user-reaction/server';
|
||||
|
Loading…
Reference in New Issue
Block a user