diff --git a/phone/src/Phone.tsx b/phone/src/Phone.tsx index 13ba3ce..f7e292b 100644 --- a/phone/src/Phone.tsx +++ b/phone/src/Phone.tsx @@ -5,7 +5,6 @@ import { Route } from 'react-router-dom'; import { CallModal } from './os/call/components/CallModal'; import { HomeApp } from './apps/home/components/Home'; import { Box, Paper, Slide, Typography } from '@material-ui/core'; -import { useKeyboardService } from './os/keyboard/hooks/useKeyboardService'; import { NotificationBar } from './os/notifications/components/NotificationBar'; import { Navigation } from './os/navigation-bar/components/Navigation'; import { useSimcardService } from './os/simcard/hooks/useSimcardService'; @@ -32,7 +31,10 @@ import WindowSnackbar from './ui/components/WindowSnackbar'; import { usePhone } from './os/phone/hooks/usePhone'; import { useTranslation } from 'react-i18next'; import { useSnackbar } from './ui/hooks/useSnackbar'; +import { PhoneEvents } from '../../typings/phone'; +import dayjs from 'dayjs'; import { isDefaultWallpaper } from './apps/settings/utils/isDefaultWallpaper'; +import { useKeyboardService } from './os/keyboard/hooks/useKeyboardService'; function Phone() { const { t, i18n } = useTranslation(); @@ -150,15 +152,20 @@ function Phone() { export default Phone; -InjectDebugData([ +InjectDebugData([ { app: 'PHONE', - method: 'setVisibility', + method: PhoneEvents.SET_VISIBILITY, data: true, }, { app: 'PHONE', - method: 'setPhoneReady', + method: PhoneEvents.SET_PHONE_READY, data: true, }, + { + app: 'PHONE', + method: PhoneEvents.SET_TIME, + data: dayjs().format('hh:mm'), + }, ]); diff --git a/phone/src/apps/camera/components/modal/GalleryModal.tsx b/phone/src/apps/camera/components/modal/GalleryModal.tsx index b96b68e..144450f 100644 --- a/phone/src/apps/camera/components/modal/GalleryModal.tsx +++ b/phone/src/apps/camera/components/modal/GalleryModal.tsx @@ -6,9 +6,8 @@ import DeleteIcon from '@material-ui/icons/Delete'; import ShareIcon from '@material-ui/icons/Share'; import { useHistory } from 'react-router-dom'; import { useQueryParams } from '../../../../common/hooks/useQueryParams'; -import { ICameraPhoto } from '../../hooks/useCamera'; import { ShareModal } from './ShareModal'; -import { PhotoEvents } from '../../../../../../typings/photo'; +import { GalleryPhoto, PhotoEvents } from '../../../../../../typings/photo'; import { useNuiRequest } from 'fivem-nui-react-lib'; export const GalleryModal = () => { @@ -20,8 +19,8 @@ export const GalleryModal = () => { const [shareOpen, setShareOpen] = useState(null); - const meta: ICameraPhoto = useMemo( - () => ({ id: query.id as string, image: query.image as string }), + const meta: GalleryPhoto = useMemo( + () => ({ id: parseInt(query.id), image: query.image as string }), [query], ); diff --git a/phone/src/apps/camera/components/modal/ShareModal.tsx b/phone/src/apps/camera/components/modal/ShareModal.tsx index 100c06c..bffd699 100644 --- a/phone/src/apps/camera/components/modal/ShareModal.tsx +++ b/phone/src/apps/camera/components/modal/ShareModal.tsx @@ -5,11 +5,11 @@ import MessageIcon from '@material-ui/icons/Message'; import { setClipboard } from '../../../../os/phone/hooks/useClipboard'; import useStyles from './modal.styles'; -import { ICameraPhoto } from '../../hooks/useCamera'; import { useHistory } from 'react-router-dom'; +import { GalleryPhoto } from '../../../../../../typings/photo'; interface IShareModalProps { - meta: ICameraPhoto; + meta: GalleryPhoto; referal: string; onClose(): void; } diff --git a/phone/src/apps/camera/hooks/state.ts b/phone/src/apps/camera/hooks/state.ts index 9c70cc8..a4a8c3b 100644 --- a/phone/src/apps/camera/hooks/state.ts +++ b/phone/src/apps/camera/hooks/state.ts @@ -1,7 +1,8 @@ import { atom } from 'recoil'; +import { GalleryPhoto } from '../../../../../typings/photo'; export const photoState = { - photos: atom({ + photos: atom({ key: 'galleryPhotos', default: [], }), diff --git a/phone/src/apps/camera/hooks/useCamera.ts b/phone/src/apps/camera/hooks/useCamera.ts index c49f4d6..4d7bc02 100644 --- a/phone/src/apps/camera/hooks/useCamera.ts +++ b/phone/src/apps/camera/hooks/useCamera.ts @@ -1,19 +1,14 @@ import { useCallback, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { SetterOrUpdater, useRecoilState } from 'recoil'; -import { PhotoEvents } from '../../../../../typings/photo'; -import { useNuiEvent, useNuiCallback } from 'fivem-nui-react-lib/dist/index'; +import { GalleryPhoto, PhotoEvents } from '../../../../../typings/photo'; +import { useNuiEvent, useNuiCallback } from 'fivem-nui-react-lib/'; import { useSnackbar } from '../../../ui/hooks/useSnackbar'; import { photoState } from './state'; -export interface ICameraPhoto { - id: string; - image: string; -} - interface IUseCamera { - photos: ICameraPhoto[]; - setPhotos: SetterOrUpdater; + photos: GalleryPhoto[]; + setPhotos: SetterOrUpdater; takePhoto: () => void; isLoading: boolean; } @@ -22,7 +17,7 @@ export const useCamera = (): IUseCamera => { const { t } = useTranslation(); const { addAlert } = useSnackbar(); - const [photos, setPhotos] = useRecoilState(photoState.photos); + const [photos, setPhotos] = useRecoilState(photoState.photos); const [isUploading, setUploading] = useState(false); @@ -43,7 +38,7 @@ export const useCamera = (): IUseCamera => { [addAlert, t], ); - const [_takePhoto] = useNuiCallback( + const [_takePhoto] = useNuiCallback( 'CAMERA', PhotoEvents.TAKE_PHOTO, onPhotoSuccess, diff --git a/phone/src/apps/contacts/hooks/state.ts b/phone/src/apps/contacts/hooks/state.ts index dfff261..1483da9 100644 --- a/phone/src/apps/contacts/hooks/state.ts +++ b/phone/src/apps/contacts/hooks/state.ts @@ -1,24 +1,17 @@ import { atom } from 'recoil'; +import { Contact } from '../../../../../typings/contact'; export const contactsState = { - contacts: atom({ + contacts: atom({ key: 'contactsList', default: [], }), - showModal: atom({ + showModal: atom({ key: 'showModal', default: false, }), - filterContacts: atom({ + filterContacts: atom({ key: 'filterContacts', default: '', }), - showContactsModal: atom({ - key: 'showContactModal', - default: false, - }), - contactDetail: atom({ - key: 'contactDetail', - default: null, - }), }; diff --git a/phone/src/apps/contacts/hooks/useFilteredContacts.ts b/phone/src/apps/contacts/hooks/useFilteredContacts.ts index 342ef2f..75f761b 100644 --- a/phone/src/apps/contacts/hooks/useFilteredContacts.ts +++ b/phone/src/apps/contacts/hooks/useFilteredContacts.ts @@ -3,7 +3,7 @@ import { contactsState } from './state'; interface FilterdContactsProps { filteredContacts: string; - setFilteredContacts: (contact: any) => void; + setFilteredContacts: (searchTerm: string) => void; } export const useFilteredContacts = (): FilterdContactsProps => { diff --git a/phone/src/apps/dialer/components/views/DialerHistory.tsx b/phone/src/apps/dialer/components/views/DialerHistory.tsx index 2e9d3c5..6bde522 100644 --- a/phone/src/apps/dialer/components/views/DialerHistory.tsx +++ b/phone/src/apps/dialer/components/views/DialerHistory.tsx @@ -8,7 +8,7 @@ import { ListItem } from '../../../../ui/components/ListItem'; import { useNuiRequest } from 'fivem-nui-react-lib'; import { useSimcard } from '../../../../os/simcard/hooks/useSimcard'; import { useContacts } from '../../../contacts/hooks/useContacts'; -import { CallEvents, ICall } from '../../../../../../typings/call'; +import { CallEvents, CallHistoryItem } from '../../../../../../typings/call'; import { useTranslation } from 'react-i18next'; import { Box, IconButton, ListItemIcon, ListItemText } from '@material-ui/core'; import { useHistory } from 'react-router-dom'; @@ -56,7 +56,7 @@ export const DialerHistory = ({ calls }) => { return ( - {calls.map((call: ICall) => + {calls.map((call: CallHistoryItem) => call.transmitter === myNumber ? ( diff --git a/phone/src/apps/dialer/hooks/state.ts b/phone/src/apps/dialer/hooks/state.ts index 2833fce..d3f3748 100644 --- a/phone/src/apps/dialer/hooks/state.ts +++ b/phone/src/apps/dialer/hooks/state.ts @@ -1,7 +1,8 @@ import { atom } from 'recoil'; +import { CallHistoryItem } from '../../../../../typings/call'; export const dialState = { - history: atom({ + history: atom({ key: 'dialHistory', default: [], }), diff --git a/phone/src/apps/dialer/hooks/useDialHistory.ts b/phone/src/apps/dialer/hooks/useDialHistory.ts index caf4bd8..d7d07f8 100644 --- a/phone/src/apps/dialer/hooks/useDialHistory.ts +++ b/phone/src/apps/dialer/hooks/useDialHistory.ts @@ -1,7 +1,6 @@ import { useRecoilValue } from 'recoil'; -import { ICall } from '../../../../../typings/call'; import { dialState } from './state'; export const useDialHistory = () => { - return useRecoilValue(dialState.history); + return useRecoilValue(dialState.history); }; diff --git a/phone/src/apps/marketplace/hooks/state.ts b/phone/src/apps/marketplace/hooks/state.ts index b81618a..77481ed 100644 --- a/phone/src/apps/marketplace/hooks/state.ts +++ b/phone/src/apps/marketplace/hooks/state.ts @@ -1,7 +1,8 @@ import { atom } from 'recoil'; +import { MarketplaceListing } from '../../../../../typings/marketplace'; export const selloutState = { - listing: atom({ + listing: atom({ key: 'listing', default: [], }), diff --git a/phone/src/apps/match/components/BottomNavigation.tsx b/phone/src/apps/match/components/BottomNavigation.tsx index 70075b5..a7d8b5e 100644 --- a/phone/src/apps/match/components/BottomNavigation.tsx +++ b/phone/src/apps/match/components/BottomNavigation.tsx @@ -15,8 +15,6 @@ const useStyles = makeStyles({ export function MatchBottomNavigation({ activePage, handleChange }) { const classes = useStyles(); - console.log(activePage); - return ( } /> diff --git a/phone/src/apps/match/hooks/state.ts b/phone/src/apps/match/hooks/state.ts index 2d86410..dd4c255 100644 --- a/phone/src/apps/match/hooks/state.ts +++ b/phone/src/apps/match/hooks/state.ts @@ -1,7 +1,8 @@ import { atom } from 'recoil'; +import { FormattedMatch, FormattedProfile } from '../../../../../typings/match'; export const matchState = { - profiles: atom({ + profiles: atom({ key: 'profiles', default: null, }), @@ -9,19 +10,19 @@ export const matchState = { key: 'errorLoadingProfiles', default: false, }), - matches: atom({ + matches: atom({ key: 'matches', default: null, }), - errorLoadingMatches: atom({ + errorLoadingMatches: atom({ key: 'errorLoadingMatches', default: false, }), - myProfile: atom({ + myProfile: atom({ key: 'myProfile', default: null, }), - noProfileExists: atom({ + noProfileExists: atom({ key: 'noProfileExists', default: false, }), diff --git a/phone/src/apps/messages/hooks/state.ts b/phone/src/apps/messages/hooks/state.ts index 5bd86c8..54e8bde 100644 --- a/phone/src/apps/messages/hooks/state.ts +++ b/phone/src/apps/messages/hooks/state.ts @@ -1,32 +1,33 @@ import { atom } from 'recoil'; +import { CreateMessageGroupResult, Message, MessageGroup } from '../../../../../typings/messages'; export const messageState = { - messageGroups: atom({ + messageGroups: atom({ key: 'messageGroups', - default: null, + default: [], }), - messages: atom({ + messages: atom({ key: 'messages', default: null, }), - activeMessageGroup: atom({ + activeMessageGroup: atom({ key: 'activeMessageGroup', default: null, }), - showNewMessageGroup: atom({ + showNewMessageGroup: atom({ key: 'showNewMessageGroup', default: false, }), - createMessageGroupResult: atom({ + createMessageGroupResult: atom({ key: 'createMessageGroupResult', default: null, }), - imageModal: atom({ + imageModal: atom({ key: 'useImageModal', default: false, }), - unreadMessagesCount: atom({ + unreadMessagesCount: atom({ key: 'unreadMessagesCount', default: 0, - }) + }), }; diff --git a/phone/src/apps/messages/hooks/useMessages.ts b/phone/src/apps/messages/hooks/useMessages.ts index 1c7836d..910efe9 100644 --- a/phone/src/apps/messages/hooks/useMessages.ts +++ b/phone/src/apps/messages/hooks/useMessages.ts @@ -72,6 +72,6 @@ const useMessages = (): IUseMessages => { setActiveMessageGroup, goToConversation, }; -}; +} export default useMessages; diff --git a/phone/src/apps/settings/hooks/useSettings.ts b/phone/src/apps/settings/hooks/useSettings.ts index 9461260..e9f3fec 100644 --- a/phone/src/apps/settings/hooks/useSettings.ts +++ b/phone/src/apps/settings/hooks/useSettings.ts @@ -104,7 +104,7 @@ const localStorageEffect = (key) => ({ setSelf, onSet }) => { }); }; -export const settingsState = atom({ +export const settingsState = atom({ key: 'settings', default: config.defaultSettings, effects_UNSTABLE: [localStorageEffect(NPWD_STORAGE_KEY)], diff --git a/phone/src/os/call/components/CallNotification.tsx b/phone/src/os/call/components/CallNotification.tsx index 685ab45..579df16 100644 --- a/phone/src/os/call/components/CallNotification.tsx +++ b/phone/src/os/call/components/CallNotification.tsx @@ -2,10 +2,10 @@ import React from 'react'; import { Box, makeStyles } from '@material-ui/core'; import { CallControls } from './CallControls'; -interface ICallNotificationProps { - onAccept(): void; - onReject(): void; -} +// interface ICallNotificationProps { +// onAccept(): void; +// onReject(): void; +// } const useStyles = makeStyles((theme) => ({ root: { diff --git a/phone/src/os/call/hooks/state.ts b/phone/src/os/call/hooks/state.ts index 88e37d9..609bcaf 100644 --- a/phone/src/os/call/hooks/state.ts +++ b/phone/src/os/call/hooks/state.ts @@ -1,11 +1,12 @@ import { atom } from 'recoil'; +import { ActiveCall } from '../../../../../typings/call'; export const callerState = { - currentCall: atom({ + currentCall: atom({ key: 'currentCall', default: null, }), - callModal: atom({ + callModal: atom({ key: 'callingModal', default: false, }), diff --git a/phone/src/os/call/hooks/useCall.ts b/phone/src/os/call/hooks/useCall.ts index 6b10478..2c3bf05 100644 --- a/phone/src/os/call/hooks/useCall.ts +++ b/phone/src/os/call/hooks/useCall.ts @@ -1,11 +1,11 @@ import { useRecoilState } from 'recoil'; -import { CallProps } from '../../../../../typings/call'; +import { ActiveCall } from '../../../../../typings/call'; import { callerState } from './state'; import { CallEvents } from '../../../../../typings/call'; import { useNuiRequest } from 'fivem-nui-react-lib'; interface CallHook { - call: CallProps; + call: ActiveCall; setCall: (details: any) => void; acceptCall(): void; rejectCall(): void; diff --git a/phone/src/os/call/hooks/useCallNotifications.tsx b/phone/src/os/call/hooks/useCallNotifications.tsx index 9d460ac..46b47a6 100644 --- a/phone/src/os/call/hooks/useCallNotifications.tsx +++ b/phone/src/os/call/hooks/useCallNotifications.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { useTranslation } from 'react-i18next'; import { useHistory } from 'react-router-dom'; -import { CallProps } from '../../../../../typings/call'; +import { ActiveCall } from '../../../../../typings/call'; import { useApp } from '../../apps/hooks/useApps'; import { useNotifications } from '../../notifications/hooks/useNotifications'; import { useRingtoneSound } from '../../sound/hooks/useRingtoneSound'; @@ -27,7 +27,7 @@ export const useCallNotifications = () => { notificationIcon, }; - const setNotification = (call: CallProps) => { + const setNotification = (call: ActiveCall) => { stop(); if (!call || !call.active) { removeId(NOTIFICATION_ID); diff --git a/phone/src/os/call/hooks/useCallService.tsx b/phone/src/os/call/hooks/useCallService.tsx index 6bb3fb3..f793715 100644 --- a/phone/src/os/call/hooks/useCallService.tsx +++ b/phone/src/os/call/hooks/useCallService.tsx @@ -1,7 +1,8 @@ import { useEffect, useState } from 'react'; import { useSetRecoilState } from 'recoil'; import { useCall } from './useCall'; -import { CallEvents, CallProps } from '../../../../../typings/call'; + +import { CallEvents, ActiveCall } from '../../../../../typings/call'; // import InjectDebugData from '../../debug/InjectDebugData'; import { useCallModal } from './useCallModal'; import { useHistory, useLocation } from 'react-router-dom'; @@ -54,7 +55,7 @@ export const useCallService = () => { } }, [history, modal, pathname, modalHasBeenOpenedThisCall]); - const _setCall = (_call: CallProps) => { + const _setCall = (_call: ActiveCall) => { setCall({ ...call, ..._call }); setNotification(_call); }; diff --git a/phone/src/os/phone/hooks/settingState.ts b/phone/src/os/phone/hooks/settingState.ts deleted file mode 100644 index a8edf73..0000000 --- a/phone/src/os/phone/hooks/settingState.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { atom } from 'recoil'; - -export const phoneSettings = { - theme: atom({ - key: 'settingTheme', - default: 'default-dark', - }), - zoom: atom({ - key: 'settingZoom', - default: '100%', - }), -}; diff --git a/phone/src/os/phone/hooks/state.ts b/phone/src/os/phone/hooks/state.ts index 522d618..e35284d 100644 --- a/phone/src/os/phone/hooks/state.ts +++ b/phone/src/os/phone/hooks/state.ts @@ -1,19 +1,20 @@ import { atom } from 'recoil'; +import { IServerConfig } from '../../../../../typings/config'; export const phoneState = { - visibility: atom({ + visibility: atom({ key: 'phoneVisibility', default: false, }), - phoneConfig: atom({ + phoneConfig: atom({ key: 'phoneConfig', - default: undefined, + default: null, }), - phoneReady: atom({ + phoneReady: atom({ key: 'phoneReady', default: false, }), - phoneTime: atom({ + phoneTime: atom({ key: 'phoneTime', default: null, }), diff --git a/phone/src/os/phone/hooks/usePhoneService.ts b/phone/src/os/phone/hooks/usePhoneService.ts index 8044bd0..71fbb88 100644 --- a/phone/src/os/phone/hooks/usePhoneService.ts +++ b/phone/src/os/phone/hooks/usePhoneService.ts @@ -16,8 +16,8 @@ export const usePhoneService = () => { const setPhoneConfig = useSetRecoilState(phoneState.phoneConfig); const setPhoneReady = useSetRecoilState(phoneState.phoneReady); const setPhoneTime = useSetRecoilState(phoneState.phoneTime); - useNuiEvent('PHONE', 'setVisibility', setVisibility); - useNuiEvent('PHONE', 'setPhoneReady', setPhoneReady); - useNuiEvent('PHONE', 'phoneConfig', setPhoneConfig); - useNuiEvent('PHONE', 'setTime', setPhoneTime); + useNuiEvent('PHONE', PhoneEvents.SET_VISIBILITY, setVisibility); + useNuiEvent('PHONE', PhoneEvents.SET_PHONE_READY, setPhoneReady); + useNuiEvent('PHONE', PhoneEvents.SET_CONFIG, setPhoneConfig); + useNuiEvent('PHONE', PhoneEvents.SET_TIME, setPhoneTime); }; diff --git a/phone/src/os/simcard/hooks/useSimcardService.ts b/phone/src/os/simcard/hooks/useSimcardService.ts index 61acc47..3923225 100644 --- a/phone/src/os/simcard/hooks/useSimcardService.ts +++ b/phone/src/os/simcard/hooks/useSimcardService.ts @@ -3,6 +3,7 @@ import { simcardState } from './state'; import { useSimcard } from './useSimcard'; import InjectDebugData from '../../debug/InjectDebugData'; import { useNuiEvent } from 'fivem-nui-react-lib'; +import { PhoneEvents } from '../../../../../typings/phone'; InjectDebugData([ { @@ -14,6 +15,6 @@ InjectDebugData([ export const useSimcardService = () => { const setNumber = useSetRecoilState(simcardState.number); - useNuiEvent('SIMCARD', 'setNumber', setNumber); + useNuiEvent('SIMCARD', PhoneEvents.SET_NUMBER, setNumber); return useSimcard(); }; diff --git a/phone/src/ui/components/Notification.tsx b/phone/src/ui/components/Notification.tsx index fa964d5..b3fa467 100644 --- a/phone/src/ui/components/Notification.tsx +++ b/phone/src/ui/components/Notification.tsx @@ -2,13 +2,11 @@ import React from 'react'; import Paper from '@material-ui/core/Paper'; import Snackbar from '@material-ui/core/Snackbar'; import Fade from '@material-ui/core/Fade'; -import { createMuiTheme, ThemeProvider } from '@material-ui/core'; +import { ThemeProvider } from '@material-ui/core'; import { makeStyles } from '@material-ui/core/styles'; import { usePhone } from '../../os/phone/hooks/usePhone'; -import { useRecoilState } from 'recoil'; -import { settingsState } from '../../apps/settings/hooks/useSettings'; -import themeConfig from '../../config/default.json'; +import { usePhoneTheme } from '../../os/phone/hooks/usePhoneTheme'; const useStyles = makeStyles({ paper: { @@ -25,15 +23,14 @@ function Notification({ children, handleClose, open }) { const classes = useStyles(); const { config } = usePhone(); - const [settings] = useRecoilState(settingsState); + const currentTheme = usePhoneTheme(); if (!config) return null; const { horizontal, vertical } = config.notificationPosition; - const currentTheme = () => createMuiTheme(themeConfig.themes[settings.theme.value]); return ( - + { cb(); }); -onNet(CallEvents.WAS_ACCEPTED, (channelId: number, currentCall: ICall, isTransmitter: boolean) => { - exp['mumble-voip'].SetCallChannel(channelId); - phoneCallStartAnim(); // Trigger call animation only if the call was accepted. - SendNuiMessage( - JSON.stringify({ - app: 'CALL', - method: CallEvents.SET_CALLER, - data: { - active: true, - transmitter: currentCall.transmitter, - receiver: currentCall.receiver, - isTransmitter: isTransmitter, - accepted: true, - }, - }), - ); -}); +onNet( + CallEvents.WAS_ACCEPTED, + (channelId: number, currentCall: CallHistoryItem, isTransmitter: boolean) => { + exp['mumble-voip'].SetCallChannel(channelId); + phoneCallStartAnim(); // Trigger call animation only if the call was accepted. + SendNuiMessage( + JSON.stringify({ + app: 'CALL', + method: CallEvents.SET_CALLER, + data: { + active: true, + transmitter: currentCall.transmitter, + receiver: currentCall.receiver, + isTransmitter: isTransmitter, + accepted: true, + }, + }), + ); + }, +); RegisterNuiCallbackType(CallEvents.REJECTED); // Fires when cancelling and rejecting a call. on(`__cfx_nui:${CallEvents.REJECTED}`, (data: any, cb: Function) => { @@ -115,7 +118,7 @@ function openCallModal(show: boolean) { ); } -onNet(CallEvents.SEND_HISTORY, (calls: ICall) => { +onNet(CallEvents.SEND_HISTORY, (calls: CallHistoryItem[]) => { SendNuiMessage( JSON.stringify({ app: 'DIALER', diff --git a/resources/client/cl_main.ts b/resources/client/cl_main.ts index ab10c9a..f4e97c5 100644 --- a/resources/client/cl_main.ts +++ b/resources/client/cl_main.ts @@ -55,14 +55,14 @@ const showPhone = async (): Promise => { await phoneOpenAnim(); // Animation starts before the phone is open emitNet('phone:getCredentials'); SetCursorLocation(0.9, 0.922); //Experimental - sendMessage('PHONE', 'setVisibility', true); - sendMessage('PHONE', 'setTime', time); + sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, true); + sendMessage('PHONE', PhoneEvents.SET_TIME, time); SetNuiFocus(true, true); }; const hidePhone = async (): Promise => { isPhoneOpen = false; - sendMessage('PHONE', 'setVisibility', false); + sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, false); await phoneCloseAnim(); SetNuiFocus(false, false); }; @@ -119,15 +119,15 @@ onNet(PhoneEvents.PLAYER_IS_READY, () => { AddEventHandler('onResourceStop', function (resource: string) { if (resource === GetCurrentResourceName()) { - sendMessage('PHONE', 'setVisibility', false); + sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, false); SetNuiFocus(false, false); removePhoneProp(); //Deletes the phone incase it was attached. ClearPedTasks(PlayerPedId()); //Leave here until launch as it'll fix any stuck animations. } }); -onNet('phone:sendCredentials', (number: string) => { - sendMessage('SIMCARD', 'setNumber', number); +onNet(PhoneEvents.SEND_CREDENTIALS, (number: string) => { + sendMessage('SIMCARD', PhoneEvents.SET_NUMBER, number); }); RegisterNuiCallbackType(PhoneEvents.UI_IS_READY); diff --git a/resources/client/cl_photo.ts b/resources/client/cl_photo.ts index 9068d6e..b13ecca 100644 --- a/resources/client/cl_photo.ts +++ b/resources/client/cl_photo.ts @@ -1,6 +1,7 @@ import { IPhoto, PhotoEvents } from '../../typings/photo'; import { Delay } from '../utils/fivem'; import { sendMessage, sendCameraEvent } from '../utils/messages'; +import { PhoneEvents } from '../../typings/phone'; const SCREENSHOT_BASIC_TOKEN = GetConvar('SCREENSHOT_BASIC_TOKEN', 'none'); const exp = (global as any).exports; @@ -9,12 +10,12 @@ let inCameraMode = false; function closePhoneTemp() { SetNuiFocus(false, false); - sendMessage('PHONE', 'setVisibility', false); + sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, false); } function openPhoneTemp() { SetNuiFocus(true, true); - sendMessage('PHONE', 'setVisibility', true); + sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, true); } function CellFrontCamActivate(activate: boolean) { diff --git a/resources/server/sv_call.ts b/resources/server/sv_call.ts index 30cbb86..e9f6bc0 100644 --- a/resources/server/sv_call.ts +++ b/resources/server/sv_call.ts @@ -1,7 +1,7 @@ import { CallEvents } from '../../typings/call'; import { getIdentifierByPhoneNumber, getPlayer, getSource } from './functions'; import { getPlayerFromIdentifier } from './functions'; -import { ICall } from '../../typings/call'; +import { CallHistoryItem } from '../../typings/call'; import { pool } from './db'; import { v4 as uuidv4 } from 'uuid'; @@ -9,25 +9,25 @@ import { mainLogger } from './sv_logger'; const callLogger = mainLogger.child({ module: 'calls' }); -async function saveCall(call: ICall) { +async function saveCall(call: CallHistoryItem) { const query = 'INSERT INTO npwd_calls (identifier, transmitter, receiver, start) VALUES (?, ?, ?, ?)'; await pool.query(query, [call.identifier, call.transmitter, call.receiver, call.start]); } -async function updateCall(call: ICall, isAccepted: boolean, end: number) { +async function updateCall(call: CallHistoryItem, isAccepted: boolean, end: number) { const query = 'UPDATE npwd_calls SET is_accepted=?, end=? WHERE identifier = ?'; await pool.query(query, [isAccepted, end, call.identifier]); } -async function fetchCalls(phoneNumber: string): Promise { +async function fetchCalls(phoneNumber: string): Promise { const query = 'SELECT * FROM npwd_calls WHERE receiver = ? OR transmitter = ? ORDER BY id DESC'; const [result] = await pool.query(query, [phoneNumber, phoneNumber]); - const calls = result; + const calls = result; return calls; } -let calls: Map = new Map(); +let calls: Map = new Map(); onNet(CallEvents.INITIALIZE_CALL, async (phoneNumber: string) => { const _source = getSource(); diff --git a/resources/server/sv_main.ts b/resources/server/sv_main.ts index 8f50896..80818ac 100644 --- a/resources/server/sv_main.ts +++ b/resources/server/sv_main.ts @@ -1,6 +1,7 @@ import { pool } from './db'; import { getIdentifier, getSource } from './functions'; import { mainLogger } from './sv_logger'; +import { PhoneEvents } from '../../typings/phone'; interface Credentials { phone_number: string; @@ -19,7 +20,7 @@ onNet('phone:getCredentials', async () => { try { const identifier = getIdentifier(_source); const number = await getCredentials(identifier); - emitNet('phone:sendCredentials', _source, number); + emitNet(PhoneEvents.SEND_CREDENTIALS, _source, number); } catch (e) { mainLogger.error(`Failed to get a number, ${e.message}`, { source: _source, diff --git a/resources/server/sv_photo.ts b/resources/server/sv_photo.ts index 9c18270..6d2dc0d 100644 --- a/resources/server/sv_photo.ts +++ b/resources/server/sv_photo.ts @@ -1,6 +1,6 @@ import { pool } from './db'; import { getIdentifier, getSource } from './functions'; -import { IPhoto, PhotoEvents } from '../../typings/photo'; +import { GalleryPhoto, PhotoEvents } from '../../typings/photo'; import { mainLogger } from './sv_logger'; const photoLogger = mainLogger.child({ module: 'photo' }); @@ -11,13 +11,13 @@ async function uploadPhoto(identifier: string, image: string): Promise { return { id: results.insertId, image }; } -async function getPhotosByIdentifier(identifier: string): Promise { +async function getPhotosByIdentifier(identifier: string): Promise { const query = 'SELECT id, image FROM npwd_phone_gallery WHERE identifier = ? ORDER BY id DESC'; const [results] = await pool.query(query, [identifier]); - return results; + return results; } -async function deletePhoto(photo: IPhoto, identifier: string) { +async function deletePhoto(photo: GalleryPhoto, identifier: string) { const query = 'DELETE FROM npwd_phone_gallery WHERE image = ? AND identifier = ?'; await pool.query(query, [photo.image, identifier]); } @@ -48,7 +48,7 @@ onNet(PhotoEvents.FETCH_PHOTOS, async () => { } }); -onNet(PhotoEvents.DELETE_PHOTO, async (photo: IPhoto) => { +onNet(PhotoEvents.DELETE_PHOTO, async (photo: GalleryPhoto) => { const _source = getSource(); try { const identifier = getIdentifier(_source); diff --git a/typings/call.ts b/typings/call.ts index 111c2a2..0e3dd25 100644 --- a/typings/call.ts +++ b/typings/call.ts @@ -1,4 +1,4 @@ -export interface CallProps { +export interface ActiveCall { active: boolean; accepted: boolean; isTransmitter: boolean; @@ -6,7 +6,7 @@ export interface CallProps { receiver: string; } -export interface ICall { +export interface CallHistoryItem { id?: number; identifier: string; transmitter: string; @@ -18,13 +18,6 @@ export interface ICall { accepted: boolean; } -export interface ICallDuration { - ms: number; - s: number; - m: number; - h: number; -} - export enum CallEvents { INITIALIZE_CALL = 'npwd:beginCall', START_CALL = 'npwd:startCall', diff --git a/typings/phone.ts b/typings/phone.ts index ae71cea..7de8f12 100644 --- a/typings/phone.ts +++ b/typings/phone.ts @@ -12,5 +12,11 @@ export enum PhoneEvents { OPEN_PHONE = 'npwd:open', CLOSE_PHONE = 'npwd:close', SET_ALERT = 'npwd:setAlert', + SET_VISIBILITY = 'npwd:setVisibility', SET_NOTIFICATION = 'npwd:setNotification', + SET_NUMBER = 'npwd:setNumber', + SET_PHONE_READY = 'npwd:phoneReady', + SET_CONFIG = 'npwd:setPhoneConfig', + SET_TIME = 'npwd:setGameTime', + SEND_CREDENTIALS = 'npwd:sendCredentials', } diff --git a/typings/photo.ts b/typings/photo.ts index 8b49b0a..d4d1f03 100644 --- a/typings/photo.ts +++ b/typings/photo.ts @@ -1,4 +1,4 @@ -export interface IPhoto { +export interface GalleryPhoto { image: string; id: number; }