From 8266b473a5dd24b7ddae4bd7d0c748aaf6b31488 Mon Sep 17 00:00:00 2001 From: Christopher Date: Mon, 11 Jan 2021 19:10:20 +0100 Subject: [PATCH 01/11] inital ts commit --- resources/client/cl_call.lua | 19 ------------------- resources/client/cl_call.ts | 15 +++++++++++++++ resources/server/sv_call.ts | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 19 deletions(-) delete mode 100644 resources/client/cl_call.lua create mode 100644 resources/client/cl_call.ts create mode 100644 resources/server/sv_call.ts diff --git a/resources/client/cl_call.lua b/resources/client/cl_call.lua deleted file mode 100644 index 6b710c2..0000000 --- a/resources/client/cl_call.lua +++ /dev/null @@ -1,19 +0,0 @@ -ESX = nil - -Citizen.CreateThread(function() - while ESX == nil do - TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) - Citizen.Wait(0) - end -end) - -RegisterNUICallback('phone:startCall', function(data) - local phoneNumber = data.number - TriggerServerEvent('phone:beginCall', phoneNumber) -end) - -RegisterNetEvent('phone:startCall') -AddEventHandler('phone:startCall', function(partner, phoneNumber, id) - print('You are talking to ' .. partner .. ', who has the number: ' .. phoneNumber); - exports["mumble-voip"]:SetCallChannel(id+1) -end) diff --git a/resources/client/cl_call.ts b/resources/client/cl_call.ts new file mode 100644 index 0000000..7a79533 --- /dev/null +++ b/resources/client/cl_call.ts @@ -0,0 +1,15 @@ +import { ESX } from './client'; +import events from '../utils/events'; + +const exp = (global as any).exports; + +RegisterNuiCallbackType(events.PHONE_BEGIN_CALL); +on(`__cfx_nui:${events.PHONE_BEGIN_CALL}`, (data: any) => { + emitNet(events.PHONE_BEGIN_CALL, data.number) +}) + + +onNet(events.PHONE_START_CALL, (target: string, phoneNumber: string, id: any) => { + console.log(`You are talking to ${target} who as the number ${phoneNumber}`); + exp["mumble-voip"].SetCallChannel(id+1) +}) diff --git a/resources/server/sv_call.ts b/resources/server/sv_call.ts new file mode 100644 index 0000000..9865c5a --- /dev/null +++ b/resources/server/sv_call.ts @@ -0,0 +1,34 @@ +import { ESX } from './server'; +import events from '../utils/events'; +import { getIdentifierByPhoneNumber, usePhoneNumber } from './functions'; + + +function getSourceFromIdentifier(identifier: string, cb: Function) { + const xPlayers = ESX.GetPlayers(); + + for (let i = 0; i < xPlayers; i++) { + const xPlayer = ESX.GetPlayerFromId(xPlayers[i]); + if (xPlayer.getIdentifier() != null && xPlayer.getIdentifier() == identifier) { + cb(xPlayer.source) + return; + } + } + cb(null); +} + +onNet(events.PHONE_BEGIN_CALL, async (phoneNumber: string) => { + const pSource = (global as any).source; + const xPlayer = ESX.GetPlayerFromId(pSource); + + const _identifier = xPlayer.getIdentifier() + const callerName = xPlayer.getName() + const callerNumber = usePhoneNumber(_identifier); + + const targetIdentifier = await getIdentifierByPhoneNumber(phoneNumber); + getSourceFromIdentifier(targetIdentifier, (target: any) => { + const xTarget = ESX.GetPlayerFromId(target); + const targetName = xTarget.getName() + emitNet(events.PHONE_START_CALL, target, callerName, callerNumber, pSource); + emitNet(events.PHONE_START_CALL, pSource, targetName, phoneNumber, target); + }) +}) From 4823debf2dbca3a929c2f029706098159f88bc3b Mon Sep 17 00:00:00 2001 From: Christopher Date: Tue, 12 Jan 2021 21:31:49 +0100 Subject: [PATCH 02/11] fix(calling/server|client): fixed events issue | updated calling server --- resources/server/sv_call.lua | 64 ------------------------------------ resources/utils/events.ts | 4 +++ 2 files changed, 4 insertions(+), 64 deletions(-) delete mode 100644 resources/server/sv_call.lua diff --git a/resources/server/sv_call.lua b/resources/server/sv_call.lua deleted file mode 100644 index 702400c..0000000 --- a/resources/server/sv_call.lua +++ /dev/null @@ -1,64 +0,0 @@ -ESX = nil - -TriggerEvent( - "esx:getSharedObject", - function(obj) - ESX = obj - end -) - -function getIdentifierByNumber(phoneNumber) - local result = MySQL.Sync.fetchAll("SELECT identifier FROM users WHERE phone_number = @phone_number", { - ['@phone_number'] = phoneNumber - }) - if result[1] ~= nil then - return result[1].identifier - end - return nil -end - -function getPhoneNumber(identifier) - local result = MySQL.Sync.fetchAll("SELECT users.phone_number FROM users WHERE users.identifier = @identifier", { - ['@identifier'] = identifier - }) - if result[1] ~= nil then - return result[1].phone_number - end - return nil -end - -function getSourceFromIdentifier(identifier, cb) - local xPlayers = ESX.GetPlayers() - for i=1, #xPlayers, 1 do - local xPlayer = ESX.GetPlayerFromId(xPlayers[i]) - if(xPlayer.identifier ~= nil and xPlayer.identifier == identifier) or (xPlayer.identifier == identifier) then - cb(xPlayer.source) - return - end - end - cb(nil) -end - -function getPlayerID(source) - local identifiers = GetPlayerIdentifiers(source) - local player = getIdentifiant(identifiers) - return player -end - -RegisterServerEvent('phone:beginCall') -AddEventHandler('phone:beginCall', function(phoneNumber) - local _source = source - local xPlayer = ESX.GetPlayerFromId(_source) - local _identifier = xPlayer.getIdentifier() - local callerName = xPlayer.getName() - local callerNumber = getPhoneNumber(_identifier); - - - local targetIdentifier = getIdentifierByNumber(phoneNumber) - getSourceFromIdentifier(targetIdentifier, function(target) - local xTarget = ESX.GetPlayerFromId(target) - local targetName = xTarget.getName() - TriggerClientEvent('phone:startCall', target, callerName, callerNumber, _source) - TriggerClientEvent('phone:startCall', _source, targetName, phoneNumber, target) - end) -end) diff --git a/resources/utils/events.ts b/resources/utils/events.ts index 1cf685b..18bff72 100644 --- a/resources/utils/events.ts +++ b/resources/utils/events.ts @@ -94,4 +94,8 @@ export default { CONTACTS_ACTION_RESULT: 'phone:contactActionResult', // copy PHONE_USE_CLIPBOARD: 'phone:useClipboard', + + // calling + PHONE_BEGIN_CALL: 'phone:beginCall', + PHONE_START_CALL: 'phone:startCall' } From 4a193776ec5b4e5fc1a8dec57488d4f6714ddfe4 Mon Sep 17 00:00:00 2001 From: Christopher Date: Tue, 12 Jan 2021 22:01:24 +0100 Subject: [PATCH 03/11] feat(calling/client|nui): new command and changed event name --- .../apps/contacts/components/List/ContactList.tsx | 2 +- resources/client/cl_call.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/phone/src/apps/contacts/components/List/ContactList.tsx b/phone/src/apps/contacts/components/List/ContactList.tsx index 3fc0d80..422865b 100644 --- a/phone/src/apps/contacts/components/List/ContactList.tsx +++ b/phone/src/apps/contacts/components/List/ContactList.tsx @@ -51,7 +51,7 @@ export const ContactList = () => { }; const startCall = (number) => { console.log(number); - Nui.send('phone:startCall', { + Nui.send('phone:beginCall', { number, }); }; diff --git a/resources/client/cl_call.ts b/resources/client/cl_call.ts index 7a79533..c3db846 100644 --- a/resources/client/cl_call.ts +++ b/resources/client/cl_call.ts @@ -3,6 +3,20 @@ import events from '../utils/events'; const exp = (global as any).exports; +RegisterCommand('call', (source: number, args: string[], raw: any) => { + emitNet(events.PHONE_BEGIN_CALL, args[0]) +}, false) + + +setImmediate(() => { + emit('chat:addSuggestion', '/call', 'Call a player', [ + { + name: 'Phone Number', + help: 'The phone number to call' + } + ]) +}) + RegisterNuiCallbackType(events.PHONE_BEGIN_CALL); on(`__cfx_nui:${events.PHONE_BEGIN_CALL}`, (data: any) => { emitNet(events.PHONE_BEGIN_CALL, data.number) From 6cfc9ec19c1ae3f024bb97a7a5433a4e497b8b66 Mon Sep 17 00:00:00 2001 From: itschip Date: Tue, 12 Jan 2021 21:02:42 +0000 Subject: [PATCH 04/11] Prettified Code! --- resources/client/cl_call.ts | 45 +++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/resources/client/cl_call.ts b/resources/client/cl_call.ts index c3db846..f37e64b 100644 --- a/resources/client/cl_call.ts +++ b/resources/client/cl_call.ts @@ -1,29 +1,36 @@ -import { ESX } from './client'; -import events from '../utils/events'; +import { ESX } from "./client"; +import events from "../utils/events"; const exp = (global as any).exports; -RegisterCommand('call', (source: number, args: string[], raw: any) => { - emitNet(events.PHONE_BEGIN_CALL, args[0]) -}, false) - +RegisterCommand( + "call", + (source: number, args: string[], raw: any) => { + emitNet(events.PHONE_BEGIN_CALL, args[0]); + }, + false +); setImmediate(() => { - emit('chat:addSuggestion', '/call', 'Call a player', [ + emit("chat:addSuggestion", "/call", "Call a player", [ { - name: 'Phone Number', - help: 'The phone number to call' - } - ]) -}) + name: "Phone Number", + help: "The phone number to call", + }, + ]); +}); RegisterNuiCallbackType(events.PHONE_BEGIN_CALL); on(`__cfx_nui:${events.PHONE_BEGIN_CALL}`, (data: any) => { - emitNet(events.PHONE_BEGIN_CALL, data.number) -}) + emitNet(events.PHONE_BEGIN_CALL, data.number); +}); - -onNet(events.PHONE_START_CALL, (target: string, phoneNumber: string, id: any) => { - console.log(`You are talking to ${target} who as the number ${phoneNumber}`); - exp["mumble-voip"].SetCallChannel(id+1) -}) +onNet( + events.PHONE_START_CALL, + (target: string, phoneNumber: string, id: any) => { + console.log( + `You are talking to ${target} who as the number ${phoneNumber}` + ); + exp["mumble-voip"].SetCallChannel(id + 1); + } +); From dec6614b45674a96a432f5a90bbe4b139c726cba Mon Sep 17 00:00:00 2001 From: Christopher Date: Tue, 12 Jan 2021 22:11:40 +0100 Subject: [PATCH 05/11] feat(client/server): imports --- resources/client/client.ts | 1 + resources/server/server.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/resources/client/client.ts b/resources/client/client.ts index af21f2a..6131b42 100644 --- a/resources/client/client.ts +++ b/resources/client/client.ts @@ -8,6 +8,7 @@ import './cl_bank'; import './cl_notes'; import './cl_photo'; import './cl_messages'; +import './cl_call'; export let ESX: Client = null; diff --git a/resources/server/server.ts b/resources/server/server.ts index 67d2fe1..dd24c34 100644 --- a/resources/server/server.ts +++ b/resources/server/server.ts @@ -9,6 +9,7 @@ import './sv_bank'; import './sv_notes'; import './sv_photo'; import './sv_messages'; +import './sv_call' export let ESX: Server = null; From 5766da5c66eb07b02a260a39f6dcf0d9c067a2e1 Mon Sep 17 00:00:00 2001 From: Taso Date: Tue, 12 Jan 2021 23:12:00 -0500 Subject: [PATCH 06/11] feat(call): More progress --- resources/client/cl_call.ts | 31 ++++++++--------- resources/server/sv_call.ts | 66 +++++++++++++++++++++++-------------- 2 files changed, 57 insertions(+), 40 deletions(-) diff --git a/resources/client/cl_call.ts b/resources/client/cl_call.ts index f37e64b..989410b 100644 --- a/resources/client/cl_call.ts +++ b/resources/client/cl_call.ts @@ -1,10 +1,10 @@ -import { ESX } from "./client"; -import events from "../utils/events"; +import { ESX } from './client'; +import events from '../utils/events'; const exp = (global as any).exports; RegisterCommand( - "call", + 'call', (source: number, args: string[], raw: any) => { emitNet(events.PHONE_BEGIN_CALL, args[0]); }, @@ -12,10 +12,10 @@ RegisterCommand( ); setImmediate(() => { - emit("chat:addSuggestion", "/call", "Call a player", [ + emit('chat:addSuggestion', '/call', 'Call a player', [ { - name: "Phone Number", - help: "The phone number to call", + name: 'Phone Number', + help: 'The phone number to call', }, ]); }); @@ -25,12 +25,13 @@ on(`__cfx_nui:${events.PHONE_BEGIN_CALL}`, (data: any) => { emitNet(events.PHONE_BEGIN_CALL, data.number); }); -onNet( - events.PHONE_START_CALL, - (target: string, phoneNumber: string, id: any) => { - console.log( - `You are talking to ${target} who as the number ${phoneNumber}` - ); - exp["mumble-voip"].SetCallChannel(id + 1); - } -); +onNet(events.PHONE_START_CALL, (target: string, phoneNumber: string) => { + console.log(`You are talking to ${target} who has the number ${phoneNumber}`); + // Temporary for testing + exp['mumble-voip'].SetCallChannel(1); +}); + +onNet(events.PHONE_CALL_WAS_ENDED, () => { + console.log('Call ended'); + exp['mumble-voip'].SetCallChannel(0); +}); diff --git a/resources/server/sv_call.ts b/resources/server/sv_call.ts index 9865c5a..1bcc8c5 100644 --- a/resources/server/sv_call.ts +++ b/resources/server/sv_call.ts @@ -1,34 +1,50 @@ import { ESX } from './server'; import events from '../utils/events'; -import { getIdentifierByPhoneNumber, usePhoneNumber } from './functions'; +import { getIdentifierByPhoneNumber, getPhoneNumberFromID } from './functions'; +import { XPlayer } from 'esx.js/@types/server'; +/** + * Returns the player phoneNumber for a passed identifier + * @param identifier The players phone number + */ +function getPlayerFromIdentifier(identifier: string): Promise { + return new Promise((res, rej) => { + const xPlayers = ESX.GetPlayers(); - -function getSourceFromIdentifier(identifier: string, cb: Function) { - const xPlayers = ESX.GetPlayers(); - - for (let i = 0; i < xPlayers; i++) { - const xPlayer = ESX.GetPlayerFromId(xPlayers[i]); - if (xPlayer.getIdentifier() != null && xPlayer.getIdentifier() == identifier) { - cb(xPlayer.source) - return; + for (const player of xPlayers) { + const xPlayer = ESX.GetPlayerFromId(player); + if ( + xPlayer.getIdentifier() != null && + xPlayer.getIdentifier() == identifier + ) { + res(xPlayer); + } } - } - cb(null); + + rej(new Error('Call Target Identifier was not found in xPlayers array')); + }); } onNet(events.PHONE_BEGIN_CALL, async (phoneNumber: string) => { - const pSource = (global as any).source; - const xPlayer = ESX.GetPlayerFromId(pSource); + const callSource = (global as any).source; + const xPlayer = ESX.GetPlayerFromId(callSource); - const _identifier = xPlayer.getIdentifier() - const callerName = xPlayer.getName() - const callerNumber = usePhoneNumber(_identifier); + const _identifier = xPlayer.getIdentifier(); + const callerName = xPlayer.getName(); + const callerNumber = getPhoneNumberFromID(_identifier); - const targetIdentifier = await getIdentifierByPhoneNumber(phoneNumber); - getSourceFromIdentifier(targetIdentifier, (target: any) => { - const xTarget = ESX.GetPlayerFromId(target); - const targetName = xTarget.getName() - emitNet(events.PHONE_START_CALL, target, callerName, callerNumber, pSource); - emitNet(events.PHONE_START_CALL, pSource, targetName, phoneNumber, target); - }) -}) + try { + const targetPlayer = await getPlayerFromIdentifier(phoneNumber); + const targetName = xPlayer.getName(); + + emitNet( + events.PHONE_START_CALL, + targetPlayer.source, + callerName, + phoneNumber + ); + emitNet(events.PHONE_START_CALL, targetName, callerNumber); + } catch (e) { + console.error(e); + emit(events.PHONE_CALL_ERORR, callSource); + } +}); From bcdab48bdba943e496ba34d70aa098a19df53e0f Mon Sep 17 00:00:00 2001 From: TasoOneAsia Date: Wed, 13 Jan 2021 04:13:28 +0000 Subject: [PATCH 07/11] Prettified Code! --- resources/client/cl_call.ts | 18 +++++++++--------- resources/server/sv_call.ts | 10 +++++----- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/resources/client/cl_call.ts b/resources/client/cl_call.ts index 989410b..9572a4d 100644 --- a/resources/client/cl_call.ts +++ b/resources/client/cl_call.ts @@ -1,10 +1,10 @@ -import { ESX } from './client'; -import events from '../utils/events'; +import { ESX } from "./client"; +import events from "../utils/events"; const exp = (global as any).exports; RegisterCommand( - 'call', + "call", (source: number, args: string[], raw: any) => { emitNet(events.PHONE_BEGIN_CALL, args[0]); }, @@ -12,10 +12,10 @@ RegisterCommand( ); setImmediate(() => { - emit('chat:addSuggestion', '/call', 'Call a player', [ + emit("chat:addSuggestion", "/call", "Call a player", [ { - name: 'Phone Number', - help: 'The phone number to call', + name: "Phone Number", + help: "The phone number to call", }, ]); }); @@ -28,10 +28,10 @@ on(`__cfx_nui:${events.PHONE_BEGIN_CALL}`, (data: any) => { onNet(events.PHONE_START_CALL, (target: string, phoneNumber: string) => { console.log(`You are talking to ${target} who has the number ${phoneNumber}`); // Temporary for testing - exp['mumble-voip'].SetCallChannel(1); + exp["mumble-voip"].SetCallChannel(1); }); onNet(events.PHONE_CALL_WAS_ENDED, () => { - console.log('Call ended'); - exp['mumble-voip'].SetCallChannel(0); + console.log("Call ended"); + exp["mumble-voip"].SetCallChannel(0); }); diff --git a/resources/server/sv_call.ts b/resources/server/sv_call.ts index 1bcc8c5..9eb4f65 100644 --- a/resources/server/sv_call.ts +++ b/resources/server/sv_call.ts @@ -1,7 +1,7 @@ -import { ESX } from './server'; -import events from '../utils/events'; -import { getIdentifierByPhoneNumber, getPhoneNumberFromID } from './functions'; -import { XPlayer } from 'esx.js/@types/server'; +import { ESX } from "./server"; +import events from "../utils/events"; +import { getIdentifierByPhoneNumber, getPhoneNumberFromID } from "./functions"; +import { XPlayer } from "esx.js/@types/server"; /** * Returns the player phoneNumber for a passed identifier * @param identifier The players phone number @@ -20,7 +20,7 @@ function getPlayerFromIdentifier(identifier: string): Promise { } } - rej(new Error('Call Target Identifier was not found in xPlayers array')); + rej(new Error("Call Target Identifier was not found in xPlayers array")); }); } From ccb5b76d295dc1d45e7216a47f49e85aa38e476a Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 15 Jan 2021 22:05:32 +0100 Subject: [PATCH 08/11] fix(contacts/nui): resolved switch statement for alerts --- phone/src/apps/contacts/components/alert/ContactAlert.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/phone/src/apps/contacts/components/alert/ContactAlert.tsx b/phone/src/apps/contacts/components/alert/ContactAlert.tsx index 67761cc..cd3278f 100644 --- a/phone/src/apps/contacts/components/alert/ContactAlert.tsx +++ b/phone/src/apps/contacts/components/alert/ContactAlert.tsx @@ -46,6 +46,7 @@ export const ContactAlert = () => { break; case 'CONTACT_UPDATE_SUCCESS': setMessageAlert(alert, 'success'); + break; } }, [alert]); From 76aee071a847bd881c3239bfddb4e6656e0b5125 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 15 Jan 2021 22:07:45 +0100 Subject: [PATCH 09/11] fix(contacts/client|server): fixed source for updating contacts --- phone/src/config/default.json | 11 +++++------ resources/client/cl_contacts.ts | 1 + resources/server/sv_contacts.ts | 23 ++++++++++++++++------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/phone/src/config/default.json b/phone/src/config/default.json index c8f5344..9a01848 100644 --- a/phone/src/config/default.json +++ b/phone/src/config/default.json @@ -2,23 +2,22 @@ "cellProvider": "AT&T", "language": "en", "wallpapers": [ - "default.png", - "dragon.jpg", - "legacy.jpg", "minimal.jpg", "waves.jpg", "surf.jpg", - "beach.jpg" + "beach.jpg", + "weeb.png", + "weeb2.gif" ], "defaultSettings": { - "wallpaper": "default.png", + "wallpaper": "minimal.png", "frame": "s10.png", "theme": "taso-dark", "zoom": "100%", "ringtone": "pixel", "ringtoneVol": 100 }, - "frames": ["default.png", "s10.png", "tw.png", "samsung.png"], + "frames": ["s10.png"], "zoomOptions": ["120%", "100%", "80%", "60%", "40%"], "ringtones": ["marimba", "pixel"], "themes": { diff --git a/resources/client/cl_contacts.ts b/resources/client/cl_contacts.ts index 8068e5a..05707c1 100644 --- a/resources/client/cl_contacts.ts +++ b/resources/client/cl_contacts.ts @@ -30,6 +30,7 @@ on(`__cfx_nui:${events.CONTACTS_UPDATE_CONTACT}`, (data: any) => { onNet(events.CONTACTS_UPDATE_CONTACT_SUCCESS, () => { emitNet(events.CONTACTS_GET_CONTACTS); + console.log("did you update the contact??????????????????"); }); RegisterNuiCallbackType(events.CONTACTS_DELETE_CONTACT); diff --git a/resources/server/sv_contacts.ts b/resources/server/sv_contacts.ts index 80281ef..2e32bb4 100644 --- a/resources/server/sv_contacts.ts +++ b/resources/server/sv_contacts.ts @@ -85,30 +85,39 @@ onNet( emitNet(events.CONTACTS_ADD_CONTACT_SUCCESS, _source); emitNet( events.CONTACTS_ACTION_RESULT, - getSource(), + _source, "CONTACT_ADD_SUCCESS" ); } catch (error) { - emitNet(events.CONTACTS_ACTION_RESULT, getSource(), "CONTACT_ADD_FAILED"); + const _source = (global as any).source; + emitNet(events.CONTACTS_ACTION_RESULT, _source, "CONTACT_ADD_FAILED"); } } ); onNet(events.CONTACTS_UPDATE_CONTACT, async (contact: Contacts) => { + console.log('let me just log the contact first', contact); try { - const _source = (global as any)._source; - const _identifier = await useIdentifier(); - updateContact(contact, _identifier); + const _source = (global as any).source; + const _identifier = ESX.GetPlayerFromId(_source).getIdentifier(); + console.log('nice identifier bro', _identifier); + await updateContact(contact, _identifier); + console.log('i updated the contact server side!'); + emitNet(events.CONTACTS_UPDATE_CONTACT_SUCCESS, _source); + console.log('ffs, didd it return successful'); + emitNet( events.CONTACTS_ACTION_RESULT, - getSource(), + _source, "CONTACT_UPDATE_SUCCESS" ); + console.log("UPDATED CONTACT: ", contact); } catch (error) { + const _source = (global as any).source; emitNet( events.CONTACTS_ACTION_RESULT, - getSource(), + _source, "CONTACT_UPDATE_FAILED" ); } From 5c168c804bef33c08da0477c09ec7b6083098565 Mon Sep 17 00:00:00 2001 From: itschip Date: Fri, 15 Jan 2021 21:08:51 +0000 Subject: [PATCH 10/11] Prettified Code! --- resources/server/sv_contacts.ts | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/resources/server/sv_contacts.ts b/resources/server/sv_contacts.ts index 2e32bb4..ebd1ed5 100644 --- a/resources/server/sv_contacts.ts +++ b/resources/server/sv_contacts.ts @@ -83,11 +83,7 @@ onNet( const _identifier = await useIdentifier(); addContact(_identifier, number, display, avatar); emitNet(events.CONTACTS_ADD_CONTACT_SUCCESS, _source); - emitNet( - events.CONTACTS_ACTION_RESULT, - _source, - "CONTACT_ADD_SUCCESS" - ); + emitNet(events.CONTACTS_ACTION_RESULT, _source, "CONTACT_ADD_SUCCESS"); } catch (error) { const _source = (global as any).source; emitNet(events.CONTACTS_ACTION_RESULT, _source, "CONTACT_ADD_FAILED"); @@ -96,30 +92,22 @@ onNet( ); onNet(events.CONTACTS_UPDATE_CONTACT, async (contact: Contacts) => { - console.log('let me just log the contact first', contact); + console.log("let me just log the contact first", contact); try { const _source = (global as any).source; const _identifier = ESX.GetPlayerFromId(_source).getIdentifier(); - console.log('nice identifier bro', _identifier); + console.log("nice identifier bro", _identifier); await updateContact(contact, _identifier); - console.log('i updated the contact server side!'); - + console.log("i updated the contact server side!"); + emitNet(events.CONTACTS_UPDATE_CONTACT_SUCCESS, _source); - console.log('ffs, didd it return successful'); - - emitNet( - events.CONTACTS_ACTION_RESULT, - _source, - "CONTACT_UPDATE_SUCCESS" - ); + console.log("ffs, didd it return successful"); + + emitNet(events.CONTACTS_ACTION_RESULT, _source, "CONTACT_UPDATE_SUCCESS"); console.log("UPDATED CONTACT: ", contact); } catch (error) { const _source = (global as any).source; - emitNet( - events.CONTACTS_ACTION_RESULT, - _source, - "CONTACT_UPDATE_FAILED" - ); + emitNet(events.CONTACTS_ACTION_RESULT, _source, "CONTACT_UPDATE_FAILED"); } }); From 903e3c5f647d498e8776250ffaf7d16d5e2edb73 Mon Sep 17 00:00:00 2001 From: Christopher Date: Sun, 17 Jan 2021 14:29:56 +0100 Subject: [PATCH 11/11] feat(modals/call/nui): inital commit for calling modal --- phone/src/modal/components/CallModal.tsx | 75 ++++++++++++++++------ phone/src/modal/components/modal.styles.ts | 18 ++++++ phone/src/modal/hooks/state.ts | 10 ++- phone/src/modal/hooks/useCall.ts | 12 +++- phone/src/modal/hooks/useCallService.ts | 8 ++- phone/src/modal/hooks/useModal.ts | 12 ++++ 6 files changed, 109 insertions(+), 26 deletions(-) create mode 100644 phone/src/modal/components/modal.styles.ts create mode 100644 phone/src/modal/hooks/useModal.ts diff --git a/phone/src/modal/components/CallModal.tsx b/phone/src/modal/components/CallModal.tsx index 7c7fe87..3dd9169 100644 --- a/phone/src/modal/components/CallModal.tsx +++ b/phone/src/modal/components/CallModal.tsx @@ -1,29 +1,68 @@ -import React from 'react'; -import { green } from '@material-ui/core/colors'; +import React, { useState } from 'react'; +import { Button, Fab } from '@material-ui/core'; import { AppWrapper } from '../../ui/components/AppWrapper'; import { AppTitle } from '../../ui/components/AppTitle'; import { AppContent } from '../../ui/components/AppContent'; +import { useCall } from '../hooks/useCall'; +import CallIcon from '@material-ui/icons/Call'; +import PhoneDisabledIcon from '@material-ui/icons/PhoneDisabled'; +import CallEndIcon from '@material-ui/icons/CallEnd'; +import useStyles from './modal.styles'; +import { useModal } from '../hooks/useModal'; export const CallModal = () => { + const { call, setCall } = useCall(); + const { setModal } = useModal() + const [accepted, setAccepted] = useState(false) + + const classes = useStyles() + + const handleAcceptCall = () => { + setAccepted(true) + } + + const handleRejectCall = () => { + setModal(false) + setCall(null) + } + + const handleEndCall = () => { + setModal(false) + setCall(null) + } + return ( - -

- Call -

+

{call.target}

+ +
+ {!accepted ? ( + <> + + + + + + + + ) : ( + + + + )} +
); diff --git a/phone/src/modal/components/modal.styles.ts b/phone/src/modal/components/modal.styles.ts new file mode 100644 index 0000000..17c88c4 --- /dev/null +++ b/phone/src/modal/components/modal.styles.ts @@ -0,0 +1,18 @@ +import { makeStyles, Theme } from '@material-ui/core/styles'; + +const useStyles = makeStyles((theme: Theme) => ({ + actions: { + width: '100%', + margin: 'auto', + display: 'flex', + alignContent: 'center', + justifyContent: 'center', + marginTop: '5em' + }, + actionButton: { + margin: 20 + } +})) + + +export default useStyles; \ No newline at end of file diff --git a/phone/src/modal/hooks/state.ts b/phone/src/modal/hooks/state.ts index 5205d4a..03a4814 100644 --- a/phone/src/modal/hooks/state.ts +++ b/phone/src/modal/hooks/state.ts @@ -1,8 +1,12 @@ import { atom } from 'recoil'; export const callerState = { - caller: atom({ - key: 'callerList', - default: [], + currentCall: atom({ + key: 'currentCall', + default: null }), + callModal: atom({ + key: 'callingModal', + default: false + }) }; diff --git a/phone/src/modal/hooks/useCall.ts b/phone/src/modal/hooks/useCall.ts index ecf52d0..6adc8ea 100644 --- a/phone/src/modal/hooks/useCall.ts +++ b/phone/src/modal/hooks/useCall.ts @@ -1,7 +1,13 @@ import { useRecoilState } from 'recoil'; +import { CallProps } from '../../common/typings/call'; import { callerState } from './state'; -export const useCall = () => { - const caller = useRecoilState(callerState.caller); - return { caller }; +interface CallHook { + call: CallProps; + setCall: (details: any) => void; +} + +export const useCall = (): CallHook => { + const [call, setCall] = useRecoilState(callerState.currentCall); + return { call, setCall }; }; diff --git a/phone/src/modal/hooks/useCallService.ts b/phone/src/modal/hooks/useCallService.ts index 17fcabc..e81816c 100644 --- a/phone/src/modal/hooks/useCallService.ts +++ b/phone/src/modal/hooks/useCallService.ts @@ -2,9 +2,13 @@ import { useNuiEvent } from '../../os/nui-events/hooks/useNuiEvent'; import { useSetRecoilState } from 'recoil'; import { callerState } from './state'; import { useCall } from './useCall'; +import { useModal } from './useModal'; export const useCallService = () => { - const setCaller = useSetRecoilState(callerState.caller); + const setCaller = useSetRecoilState(callerState.currentCall); + const setModal= useSetRecoilState(callerState.callModal); + useNuiEvent('CALL', 'setCaller', setCaller); - return useCall(); + useNuiEvent('CALL', 'callModal', setModal); + return { useCall, useModal }; }; diff --git a/phone/src/modal/hooks/useModal.ts b/phone/src/modal/hooks/useModal.ts new file mode 100644 index 0000000..3ac7069 --- /dev/null +++ b/phone/src/modal/hooks/useModal.ts @@ -0,0 +1,12 @@ +import { useRecoilState } from 'recoil'; +import { callerState } from './state'; + +interface ModalProps { + modal: boolean; + setModal: (show: boolean) => void; +} + +export const useModal = (): ModalProps => { + const [modal, setModal] = useRecoilState(callerState.callModal); + return { modal, setModal } +} \ No newline at end of file