migrate removePresentation action

This commit is contained in:
Ramón Souza 2024-01-23 10:55:40 -03:00
parent b674d8a912
commit 0dcb2bc7a2
11 changed files with 64 additions and 52 deletions

View File

@ -1 +0,0 @@
import './methods';

View File

@ -1,6 +0,0 @@
import { Meteor } from 'meteor/meteor';
import removePresentation from './methods/removePresentation';
Meteor.methods({
removePresentation,
});

View File

@ -1,28 +0,0 @@
import RedisPubSub from '/imports/startup/server/redis';
import { check } from 'meteor/check';
import { extractCredentials } from '/imports/api/common/server/helpers';
import Logger from '/imports/startup/server/logger';
export default function removePresentation(presentationId, podId) {
const REDIS_CONFIG = Meteor.settings.private.redis;
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
const EVENT_NAME = 'RemovePresentationPubMsg';
try {
const { meetingId, requesterUserId } = extractCredentials(this.userId);
check(meetingId, String);
check(requesterUserId, String);
check(presentationId, String);
check(podId, String);
const payload = {
presentationId,
podId,
};
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
} catch (err) {
Logger.error(`Exception while invoking method removePresentation ${err.stack}`);
}
}

View File

@ -52,6 +52,7 @@ class NotesDropdown extends PureComponent {
amIPresenter,
presentations,
setPresentation,
removePresentation,
} = this.props;
const { converterButtonDisabled } = this.state;
@ -72,7 +73,7 @@ class NotesDropdown extends PureComponent {
onClick: () => {
this.setConverterButtonDisabled(true);
setTimeout(() => this.setConverterButtonDisabled(false), DEBOUNCE_TIMEOUT);
return Service.convertAndUpload(presentations, setPresentation);
return Service.convertAndUpload(presentations, setPresentation, removePresentation);
},
},
);

View File

@ -6,7 +6,7 @@ import {
PROCESSED_PRESENTATIONS_SUBSCRIPTION,
} from '/imports/ui/components/whiteboard/queries';
import useCurrentUser from '/imports/ui/core/hooks/useCurrentUser';
import { PRESENTATION_SET_CURRENT } from '../../presentation/mutations';
import { PRESENTATION_SET_CURRENT, PRESENTATION_REMOVE } from '../../presentation/mutations';
const NotesDropdownContainer = ({ ...props }) => {
const { data: currentUserData } = useCurrentUser((user) => ({
@ -19,12 +19,29 @@ const NotesDropdownContainer = ({ ...props }) => {
const presentations = presentationData?.pres_presentation || [];
const [presentationSetCurrent] = useMutation(PRESENTATION_SET_CURRENT);
const [presentationRemove] = useMutation(PRESENTATION_REMOVE);
const setPresentation = (presentationId) => {
presentationSetCurrent({ variables: { presentationId } });
};
return <NotesDropdown {...{ amIPresenter, isRTL, presentations, setPresentation, ...props }} />;
const removePresentation = (presentationId) => {
presentationRemove({ variables: { presentationId } });
};
return (
<NotesDropdown {
...{
amIPresenter,
isRTL,
presentations,
setPresentation,
removePresentation,
...props,
}
}
/>
);
};
export default NotesDropdownContainer;

View File

@ -7,7 +7,7 @@ import { uniqueId } from '/imports/utils/string-utils';
const PADS_CONFIG = Meteor.settings.public.pads;
async function convertAndUpload(presentations, setPresentation) {
async function convertAndUpload(presentations, setPresentation, removePresentation) {
let filename = 'Shared_Notes';
const duplicates = presentations.filter((pres) => pres.filename?.startsWith(filename) || pres.name?.startsWith(filename)).length;
@ -52,7 +52,9 @@ async function convertAndUpload(presentations, setPresentation) {
onUpload: () => { },
onProgress: () => { },
onDone: () => { },
}, setPresentation);
},
setPresentation,
removePresentation);
}
export default {

View File

@ -53,10 +53,19 @@ export const PRESENTATION_SET_CURRENT = gql`
}
`;
export const PRESENTATION_REMOVE = gql`
mutation PresentationRemove($presentationId: String!) {
presentationRemove(
presentationId: $presentationId,
)
}
`;
export default {
PRESENTATION_SET_ZOOM,
PRESENTATION_SET_WRITERS,
PRESENTATION_SET_PAGE,
PRESENTATION_SET_DOWNLOADABLE,
PRESENTATION_SET_CURRENT,
PRESENTATION_REMOVE,
};

View File

@ -584,6 +584,7 @@ class PresentationUploader extends Component {
presentations: propPresentations,
dispatchChangePresentationDownloadable,
setPresentation,
removePresentation,
} = this.props;
const { disableActions, presentations } = this.state;
const presentationsToSave = presentations;
@ -611,7 +612,14 @@ class PresentationUploader extends Component {
if (!disableActions) {
Session.set('showUploadPresentationView', false);
return handleSave(presentationsToSave, true, {}, propPresentations, setPresentation)
return handleSave(
presentationsToSave,
true,
{},
propPresentations,
setPresentation,
removePresentation,
)
.then(() => {
const hasError = presentations.some((p) => !!p.uploadErrorMsgKey);
if (!hasError) {

View File

@ -17,7 +17,7 @@ import {
PRESENTATIONS_SUBSCRIPTION,
} from '/imports/ui/components/whiteboard/queries';
import useCurrentUser from '/imports/ui/core/hooks/useCurrentUser';
import { PRESENTATION_SET_DOWNLOADABLE, PRESENTATION_SET_CURRENT } from '../mutations';
import { PRESENTATION_SET_DOWNLOADABLE, PRESENTATION_SET_CURRENT, PRESENTATION_REMOVE } from '../mutations';
const PRESENTATION_CONFIG = Meteor.settings.public.presentation;
@ -33,6 +33,7 @@ const PresentationUploaderContainer = (props) => {
const [presentationSetDownloadable] = useMutation(PRESENTATION_SET_DOWNLOADABLE);
const [presentationSetCurrent] = useMutation(PRESENTATION_SET_CURRENT);
const [presentationRemove] = useMutation(PRESENTATION_REMOVE);
const exportPresentation = (presentationId, fileStateType) => {
presentationSetDownloadable({
@ -58,6 +59,10 @@ const PresentationUploaderContainer = (props) => {
presentationSetCurrent({ variables: { presentationId } });
};
const removePresentation = (presentationId) => {
presentationRemove({ variables: { presentationId } });
};
return userIsPresenter && (
<ErrorBoundary Fallback={FallbackModal}>
<PresentationUploader
@ -67,6 +72,7 @@ const PresentationUploaderContainer = (props) => {
exportPresentation={exportPresentation}
dispatchChangePresentationDownloadable={dispatchChangePresentationDownloadable}
setPresentation={setPresentation}
removePresentation={removePresentation}
{...props}
/>
</ErrorBoundary>

View File

@ -179,15 +179,18 @@ const uploadAndConvertPresentations = (
p.onUpload, p.onProgress, p.onConversion, p.current,
)));
const removePresentation = (presentationId) => {
makeCall('removePresentation', presentationId, POD_ID);
};
const removePresentations = (
presentationsToRemove,
) => Promise.all(presentationsToRemove.map((p) => removePresentation(p.presentationId, POD_ID)));
removePresentation,
) => Promise.all(presentationsToRemove.map((p) => removePresentation(p.presentationId)));
const persistPresentationChanges = (oldState, newState, uploadEndpoint, setPresentation) => {
const persistPresentationChanges = (
oldState,
newState,
uploadEndpoint,
setPresentation,
removePresentation,
) => {
const presentationsToUpload = newState.filter((p) => !p.uploadCompleted);
const presentationsToRemove = oldState.filter((p) => !newState.find((u) => { return u.presentationId === p.presentationId }));
@ -206,7 +209,7 @@ const persistPresentationChanges = (oldState, newState, uploadEndpoint, setPrese
})
.then((presentations) => {
if (currentPresentation === undefined) {
setPresentation('', POD_ID);
setPresentation('');
return Promise.resolve();
}
@ -221,9 +224,9 @@ const persistPresentationChanges = (oldState, newState, uploadEndpoint, setPrese
return Promise.resolve();
}
return setPresentation(currentPresentation?.presentationId, POD_ID);
return setPresentation(currentPresentation?.presentationId);
})
.then(removePresentations.bind(null, presentationsToRemove, POD_ID));
.then(removePresentations.bind(null, presentationsToRemove, removePresentation));
};
const handleSavePresentation = (
@ -232,6 +235,7 @@ const handleSavePresentation = (
newPres = {},
currentPresentations = [],
setPresentation,
removePresentation,
) => {
if (!isPresentationEnabled()) {
return null;
@ -254,6 +258,7 @@ const handleSavePresentation = (
presentations,
PRESENTATION_CONFIG.uploadEndpoint,
setPresentation,
removePresentation,
);
};

View File

@ -7,7 +7,6 @@ import '/imports/api/annotations/server';
import '/imports/api/cursor/server';
import '/imports/api/polls/server';
import '/imports/api/captions/server';
import '/imports/api/presentations/server';
import '/imports/api/presentation-upload-token/server';
import '/imports/api/breakouts/server';
import '/imports/api/breakouts-history/server';