mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
Merge pull request #12 from Re-Ignited-Development/feature/contacts-lua-to-ts
Feature/contacts lua to ts
This commit is contained in:
8 files changed
+36
-134
No files matched your search
+3
-3
@@ -44,19 +44,19 @@ setTimeout(() => {
|
|||||||
id: 1,
|
id: 1,
|
||||||
number: "345-4366",
|
number: "345-4366",
|
||||||
display: "Gjelten",
|
display: "Gjelten",
|
||||||
img: 'https://i.imgur.com/Qpw6j8D.png'
|
avatar: 'https://i.imgur.com/Qpw6j8D.png'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 2,
|
id: 2,
|
||||||
number: "456-4366",
|
number: "456-4366",
|
||||||
display: "Loyd",
|
display: "Loyd",
|
||||||
img: ''
|
avatar: ''
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 3,
|
id: 3,
|
||||||
number: "123-4366",
|
number: "123-4366",
|
||||||
display: "Fabian",
|
display: "Fabian",
|
||||||
img: 'https://i.imgur.com/B8ta5Aa.jpeg'
|
avatar: 'https://i.imgur.com/B8ta5Aa.jpeg'
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ export const AddContactModal = () => {
|
|||||||
fullWidth
|
fullWidth
|
||||||
placeholder="Number"
|
placeholder="Number"
|
||||||
variant="standard"
|
variant="standard"
|
||||||
type="number"
|
type="text"
|
||||||
/>
|
/>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
<ListItem>
|
<ListItem>
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ export const ContactList = () => {
|
|||||||
{contacts.contacts.filter(contact => contact.display.includes(filteredContacts) || contact.number.includes(filteredContacts)).map((contact) => (
|
{contacts.contacts.filter(contact => contact.display.includes(filteredContacts) || contact.number.includes(filteredContacts)).map((contact) => (
|
||||||
<ListItem key={contact.id} divider>
|
<ListItem key={contact.id} divider>
|
||||||
<ListItemAvatar>
|
<ListItemAvatar>
|
||||||
{contact.img ? (
|
{contact.avatar ? (
|
||||||
<MuiAvatar src={contact.img} />
|
<MuiAvatar src={contact.avatar} />
|
||||||
): (
|
): (
|
||||||
<MuiAvatar>{contact.display.slice(0, 1)}</MuiAvatar>
|
<MuiAvatar>{contact.display.slice(0, 1)}</MuiAvatar>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -10,11 +10,16 @@ onNet(events.CONTACTS_SEND_CONTACTS, (contacts: any) => {
|
|||||||
data: contacts
|
data: contacts
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
});
|
||||||
|
|
||||||
RegisterNuiCallbackType(events.CONTACTS_ADD_CONTACT_NUI);
|
RegisterNuiCallbackType(events.CONTACTS_ADD_CONTACT);
|
||||||
on(`__cfx_nui:${events.CONTACTS_ADD_CONTACT_NUI}`, (data: any) => {
|
on(`__cfx_nui:${events.CONTACTS_ADD_CONTACT}`, (data: any) => {
|
||||||
const display = data.name;
|
const display = data.name;
|
||||||
const number = data.number;
|
const number = data.number;
|
||||||
emitNet(events.CONTACTS_ADD_CONTACT, display, number);
|
const avatar = data.avatar;
|
||||||
|
emitNet(events.CONTACTS_ADD_CONTACT, number, display, avatar);
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
emitNet(events.CONTACTS_GET_CONTACTS)
|
||||||
|
}, 1000)
|
||||||
});
|
});
|
||||||
@@ -2,7 +2,6 @@ import { ESX } from './server';
|
|||||||
import { pool } from './db';
|
import { pool } from './db';
|
||||||
import events from '../utils/events';
|
import events from '../utils/events';
|
||||||
|
|
||||||
|
|
||||||
interface Contacts {
|
interface Contacts {
|
||||||
display: string;
|
display: string;
|
||||||
number: string;
|
number: string;
|
||||||
@@ -15,36 +14,35 @@ async function fetchAllContacts(identifier: string) : Promise<Contacts[]> {
|
|||||||
return contacts;
|
return contacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
onNet(events.CONTACTS_GET_CONTACTS, async (callback: any) => {
|
async function addContact(identifier: string, number: string, display: string, avatar: string):Promise<any> {
|
||||||
|
const query = "INSERT INTO npwd_phone_contacts (identifier, number, display, avatar) VALUES (?, ?, ?, ?)"
|
||||||
|
|
||||||
|
await pool.query(query, [identifier, number, display, avatar]);
|
||||||
|
}
|
||||||
|
|
||||||
|
onNet(events.CONTACTS_GET_CONTACTS, async () => {
|
||||||
try {
|
try {
|
||||||
const _source = (global as any).source;
|
const _source = (global as any).source;
|
||||||
const xPlayer = ESX.GetPlayerFromId(_source);
|
const xPlayer = ESX.GetPlayerFromId(_source);
|
||||||
const _identifier = xPlayer.getIdentifier();
|
const _identifier = xPlayer.getIdentifier();
|
||||||
|
|
||||||
const contacts = await fetchAllContacts(_identifier);
|
const contacts = await fetchAllContacts(_identifier);
|
||||||
console.log("Contacts: ")
|
|
||||||
contacts.forEach(element => {
|
|
||||||
console.log(element.display, element.number);
|
|
||||||
});
|
|
||||||
emitNet(events.CONTACTS_SEND_CONTACTS, _source, contacts)
|
emitNet(events.CONTACTS_SEND_CONTACTS, _source, contacts)
|
||||||
|
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
console.log("Failed to fetch contacts: ", error);
|
console.log("Failed to fetch contacts: ", error);
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
//RegisterServerEvent('phone:addContacts')
|
onNet(events.CONTACTS_ADD_CONTACT, (number: string, display: string, avatar: string) => {
|
||||||
//AddEventHandler('phone:addContacts', function(display, number)
|
try {
|
||||||
// local _source = source
|
const _source = (global as any).source;
|
||||||
// local xPlayer = ESX.GetPlayerFromId(_source)
|
const xPlayer = ESX.GetPlayerFromId(_source);
|
||||||
// local _identifier = xPlayer.getIdentifier()
|
const _identifier = xPlayer.getIdentifier()
|
||||||
// print(display, number)
|
addContact(_identifier, number, display, avatar);
|
||||||
// MySQL.Async.execute('INSERT INTO npwd_phone_contacts (`identifier`, `number`, `display`) VALUES (@identifier, @number, @display)',
|
emit(events.CONTACTS_GET_CONTACTS);
|
||||||
// {
|
|
||||||
// identifier = _identifier,
|
} catch(error) {
|
||||||
// number = number,
|
console.log("Failed to add contact: ", error);
|
||||||
// display = display
|
}
|
||||||
// }, function()
|
});
|
||||||
// end)
|
|
||||||
//end)
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
ESX = nil
|
|
||||||
db = DatabaseConfig -- helper variable for use in server functions
|
|
||||||
|
|
||||||
TriggerEvent('esx:getSharedObject', function(obj)
|
|
||||||
ESX = obj
|
|
||||||
end)
|
|
||||||
|
|
||||||
|
|
||||||
-- we pass the server configuration to the phone so that we can have phone or
|
|
||||||
-- app specific settings configured by the server owner
|
|
||||||
ESX.RegisterServerCallback('phone:phoneConfig', function(source, cb)
|
|
||||||
cb(Config)
|
|
||||||
end)
|
|
||||||
|
|
||||||
|
|
||||||
RegisterServerEvent('phone:getCredentials')
|
|
||||||
AddEventHandler('phone:getCredentials', function()
|
|
||||||
local _source = source
|
|
||||||
local xPlayer = ESX.GetPlayerFromId(_source)
|
|
||||||
local _identifier = xPlayer.getIdentifier()
|
|
||||||
MySQL.Async.fetchAll('SELECT ' .. db.users.phoneNumber .. ' AS phone_number FROM ' .. db.users.table .. ' WHERE ' .. db.users.id .. '=@identifier',
|
|
||||||
{
|
|
||||||
['@identifier'] = _identifier
|
|
||||||
},
|
|
||||||
function(result)
|
|
||||||
for k,v in pairs(result) do
|
|
||||||
print(v.phone_number)
|
|
||||||
number = v.phone_number
|
|
||||||
end
|
|
||||||
TriggerClientEvent('phone:sendCredentials', _source, number)
|
|
||||||
end)
|
|
||||||
TriggerClientEvent('phone:send', _source)
|
|
||||||
end)
|
|
||||||
|
|
||||||
RegisterCommand('getnumber', function(source, args)
|
|
||||||
local _source = source
|
|
||||||
local xPlayer = ESX.GetPlayerFromId(_source)
|
|
||||||
local _identifier = xPlayer.getIdentifier()
|
|
||||||
print(_identifier)
|
|
||||||
end)
|
|
||||||
|
|
||||||
ESX.RegisterServerCallback('phone:getItemAmount', function(source, cb, item)
|
|
||||||
local xPlayer = ESX.GetPlayerFromId(source)
|
|
||||||
local items = xPlayer.getInventoryItem(item)
|
|
||||||
|
|
||||||
if items == nil then
|
|
||||||
cb(0)
|
|
||||||
else
|
|
||||||
cb(items.count)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
----
|
|
||||||
--Destroy Phone
|
|
||||||
--
|
|
||||||
|
|
||||||
ESX.RegisterServerCallback('phone:removephone', function(source, cb, item)
|
|
||||||
local xPlayer = ESX.GetPlayerFromId(source)
|
|
||||||
local items = xPlayer.getInventoryItem(item)
|
|
||||||
|
|
||||||
if items == nil then
|
|
||||||
cb(0)
|
|
||||||
else
|
|
||||||
cb(items.count)
|
|
||||||
if items.count > 0 then
|
|
||||||
xPlayer.removeInventoryItem('phone', items.count)
|
|
||||||
xPlayer.addInventoryItem('dphone', items.count)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
@@ -32,35 +32,3 @@ onNet('phone:getCredentials', async () => {
|
|||||||
console.log('Failed to get number. ', error);
|
console.log('Failed to get number. ', error);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
//ESX.RegisterServerCallback('phone:getItemAmount', function(source, cb, item)
|
|
||||||
// local xPlayer = ESX.GetPlayerFromId(source)
|
|
||||||
// local items = xPlayer.getInventoryItem(item)
|
|
||||||
//
|
|
||||||
// if items == nil then
|
|
||||||
// cb(0)
|
|
||||||
// else
|
|
||||||
// cb(items.count)
|
|
||||||
// end
|
|
||||||
//end)
|
|
||||||
//
|
|
||||||
//----
|
|
||||||
//--Destroy Phone
|
|
||||||
//--
|
|
||||||
//
|
|
||||||
//ESX.RegisterServerCallback('phone:removephone', function(source, cb, item)
|
|
||||||
// local xPlayer = ESX.GetPlayerFromId(source)
|
|
||||||
// local items = xPlayer.getInventoryItem(item)
|
|
||||||
//
|
|
||||||
// if items == nil then
|
|
||||||
// cb(0)
|
|
||||||
// else
|
|
||||||
// cb(items.count)
|
|
||||||
// if items.count > 0 then
|
|
||||||
// xPlayer.removeInventoryItem('phone', items.count)
|
|
||||||
// xPlayer.addInventoryItem('dphone', items.count)
|
|
||||||
// end
|
|
||||||
// end
|
|
||||||
//end)
|
|
||||||
@@ -24,5 +24,6 @@ export default {
|
|||||||
CONTACTS_SEND_CONTACTS: 'phone:sendContacts',
|
CONTACTS_SEND_CONTACTS: 'phone:sendContacts',
|
||||||
CONTACTS_GET_CONTACTS: 'phone:getContacts',
|
CONTACTS_GET_CONTACTS: 'phone:getContacts',
|
||||||
CONTACTS_ADD_CONTACT_NUI: 'contacts:add',
|
CONTACTS_ADD_CONTACT_NUI: 'contacts:add',
|
||||||
CONTACTS_ADD_CONTACT: 'phone:addContacts'
|
CONTACTS_ADD_CONTACT: 'contacts:add',
|
||||||
|
CONTACTS_UPDATE_CONTACTS: 'phone:updateContacts'
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user