2024-06-20 01:18:58 +08:00
|
|
|
import { useCallback } from 'react';
|
2024-03-09 04:48:44 +08:00
|
|
|
import { useMutation } from '@apollo/client';
|
2024-01-29 20:49:40 +08:00
|
|
|
import { USER_SET_MUTED } from '../mutations';
|
2024-06-20 01:18:58 +08:00
|
|
|
import useCurrentUser from '/imports/ui/core/hooks/useCurrentUser';
|
2024-05-30 04:43:17 +08:00
|
|
|
import logger from '/imports/startup/client/logger';
|
2024-01-29 20:49:40 +08:00
|
|
|
|
|
|
|
const useToggleVoice = () => {
|
|
|
|
const [userSetMuted] = useMutation(USER_SET_MUTED);
|
2024-06-20 01:18:58 +08:00
|
|
|
const { data: currentUserData } = useCurrentUser((u) => ({
|
|
|
|
voice: {
|
|
|
|
muted: u.voice?.muted,
|
|
|
|
},
|
|
|
|
}));
|
2024-01-29 20:49:40 +08:00
|
|
|
|
2024-05-10 19:52:01 +08:00
|
|
|
const toggleVoice = async (userId: string, muted: boolean) => {
|
2024-05-30 04:43:17 +08:00
|
|
|
try {
|
|
|
|
await userSetMuted({ variables: { muted, userId } });
|
|
|
|
} catch (e) {
|
|
|
|
logger.error('Error on trying to toggle muted');
|
|
|
|
}
|
2024-01-29 20:49:40 +08:00
|
|
|
};
|
|
|
|
|
2024-06-20 01:18:58 +08:00
|
|
|
return useCallback(toggleVoice, [currentUserData?.voice?.muted]);
|
2024-01-29 20:49:40 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default useToggleVoice;
|