Files
new-phone-who-dis/phone/src/os/call/hooks/useCallService.tsx
T
9abac70427 feat/messages additions (in memory of Leonard Nimoy) (#118)
* feat(resouces/messages): broadcast messagse to participants

* feat(phone/messages): notifications for messages

* remove weird empty onNet

* reformat?

* last reformat! This pr will be squashed

* tweak(phone/messages): send groupName to notification alert

* fix identifer

* fixing notification groupName

* resbasee...i think

* feat(messages): check for unread messages

* send nui event is count > 0

* remove usless test

* import.sql update

* Refactor NotificationsProvider and fix messages notifications

* Send groupId on message broadcast

* Update phone/src/apps/messages/components/modal/Conversation.tsx

* Update phone/src/apps/messages/hooks/useMessageNotifications.ts

* Update phone/src/os/notifications/providers/NotificationsProvider.tsx

* Update phone/src/common/typings/messages.ts

* Update phone/src/apps/messages/hooks/useMessageNotifications.ts

* clean sql file

* Update resources/server/sv_messages.ts

* Fetch message groups when other person created for you

* fix sql

* Select unreadCount from messageGroups

* whatever husky again

* Add members menu and add contact in messages

* Add from group bubbles

* Fix messages scroll with new msg

* Message image menu flicker + justify bottom messages

* Improve debugging

* Add container to Slider

* Improve logger

* Fix create message

* add creator identifier to group hash

* Fix dafuq i broke

* group_id bigger varchar in column

* group_id bigger varchar in column

* Phone visibility default browser

* Add debugging

Co-authored-by: J Francisco Rader <[email protected]>
Co-authored-by: J Francisco Rader <[email protected]>
2021-03-04 18:35:33 -05:00

67 lines
1.8 KiB
TypeScript

import { useEffect, useState } from 'react';
import { useNuiEvent } from '../../nui-events/hooks/useNuiEvent';
import { useSetRecoilState } from 'recoil';
import { useCall } from './useCall';
import { CallProps } from '../../../common/typings/call';
import InjectDebugData from '../../debug/InjectDebugData';
import { useCallModal } from './useCallModal';
import { useHistory, useLocation } from 'react-router-dom';
import { callerState } from './state';
import { useCallNotifications } from './useCallNotifications';
import { useDuration } from './useDuration';
InjectDebugData<CallProps | boolean>([
/* {
app: 'CALL',
method: 'setCaller',
data: {
accepted: true,
isTransmitter: false,
transmitter: 'Chip',
receiver: 'Taso',
active: true,
},
},
{
app: 'CALL',
method: 'callModal',
data: true,
}, */
]);
export const useCallService = () => {
const { modal } = useCallModal();
const history = useHistory();
const { pathname } = useLocation();
const { call, setCall } = useCall();
const { resetDuration } = useDuration();
const { setNotification } = useCallNotifications();
const setModal = useSetRecoilState(callerState.callModal);
const [modalHasBeenOpenedThisCall, setModalOpened] = useState<boolean>(false);
useEffect(() => {
setModalOpened(!!modal);
}, [modal]);
useEffect(() => {
if (!modal && pathname === '/call') {
history.replace('/');
}
if (modal && !modalHasBeenOpenedThisCall && pathname !== '/call') {
history.push('/call');
}
}, [history, modal, pathname, modalHasBeenOpenedThisCall]);
const _setCall = (_call: CallProps) => {
resetDuration();
setCall(_call);
setNotification(_call);
};
useNuiEvent<CallProps>('CALL', 'setCaller', _setCall, call);
useNuiEvent<boolean>('CALL', 'callModal', setModal);
};