2023-11-30 19:08:16 +08:00
|
|
|
import React from 'react';
|
2020-06-30 10:43:20 +08:00
|
|
|
import { withTracker } from 'meteor/react-meteor-data';
|
|
|
|
import Settings from '/imports/ui/services/settings';
|
2024-03-22 22:29:15 +08:00
|
|
|
import { useMutation, useSubscription } from '@apollo/client';
|
2023-06-08 09:10:07 +08:00
|
|
|
import RaiseHandNotifier from './component';
|
2023-12-07 03:30:30 +08:00
|
|
|
import { SET_RAISE_HAND } from '/imports/ui/core/graphql/mutations/userMutations';
|
2023-11-30 19:08:16 +08:00
|
|
|
import useCurrentUser from '/imports/ui/core/hooks/useCurrentUser';
|
2024-03-22 22:29:15 +08:00
|
|
|
import { RAISED_HAND_USERS } from './queries';
|
2024-04-10 22:00:34 +08:00
|
|
|
import logger from '/imports/startup/client/logger';
|
2020-07-06 20:56:19 +08:00
|
|
|
|
2021-04-07 03:58:11 +08:00
|
|
|
const StatusNotifierContainer = (props) => {
|
2023-11-30 19:08:16 +08:00
|
|
|
const { data: currentUserData } = useCurrentUser((user) => ({
|
|
|
|
presenter: user.presenter,
|
2024-03-22 22:29:15 +08:00
|
|
|
isModerator: user.isModerator,
|
2023-11-30 19:08:16 +08:00
|
|
|
}));
|
2024-03-22 22:29:15 +08:00
|
|
|
const isViewer = !currentUserData?.isModerator;
|
2023-11-30 19:08:16 +08:00
|
|
|
const isPresenter = currentUserData?.presenter;
|
2023-12-07 03:30:30 +08:00
|
|
|
|
2024-03-22 22:29:15 +08:00
|
|
|
const {
|
|
|
|
data: usersData,
|
|
|
|
error: usersError,
|
|
|
|
} = useSubscription(RAISED_HAND_USERS);
|
|
|
|
const raiseHandUsers = usersData?.user || [];
|
|
|
|
|
|
|
|
if (usersError) {
|
2024-04-10 22:00:34 +08:00
|
|
|
logger.error({
|
|
|
|
logCode: 'raisehand_notifier_container_subscription_error',
|
|
|
|
extraInfo: { usersError },
|
|
|
|
}, 'Error on requesting raise hand data');
|
2024-03-22 22:29:15 +08:00
|
|
|
}
|
|
|
|
|
2023-12-07 03:30:30 +08:00
|
|
|
const [setRaiseHand] = useMutation(SET_RAISE_HAND);
|
|
|
|
|
|
|
|
const lowerUserHands = (userId) => {
|
|
|
|
setRaiseHand({
|
|
|
|
variables: {
|
|
|
|
userId,
|
|
|
|
raiseHand: false,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
2021-04-07 03:58:11 +08:00
|
|
|
return (
|
2023-06-08 09:10:07 +08:00
|
|
|
<RaiseHandNotifier {...{
|
2021-04-07 03:58:11 +08:00
|
|
|
...props,
|
|
|
|
isViewer,
|
2021-09-27 19:29:49 +08:00
|
|
|
isPresenter,
|
2023-12-07 03:30:30 +08:00
|
|
|
lowerUserHands,
|
2024-03-22 22:29:15 +08:00
|
|
|
raiseHandUsers,
|
2021-04-07 03:58:11 +08:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
2020-06-30 10:43:20 +08:00
|
|
|
|
2023-06-08 09:10:07 +08:00
|
|
|
export default withTracker(() => {
|
2020-06-30 10:43:20 +08:00
|
|
|
const AppSettings = Settings.application;
|
|
|
|
|
|
|
|
return {
|
|
|
|
raiseHandAudioAlert: AppSettings.raiseHandAudioAlerts,
|
|
|
|
raiseHandPushAlert: AppSettings.raiseHandPushAlerts,
|
|
|
|
};
|
|
|
|
})(StatusNotifierContainer);
|