mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
Fix(Contacts): Fixed real-time showing new contacts
This commit is contained in:
1 parent
e1b3a84323
commit
68c0ce4037
2 files changed
+28
-25
No files matched your search
@@ -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)
|
|
||||||
Reference in new issue
Block a user