diff --git a/client/main.lua b/client/main.lua index e5aa9924..4e30a3fc 100644 --- a/client/main.lua +++ b/client/main.lua @@ -109,6 +109,21 @@ AddEventHandler('esx_phone:addContact', function(name, phoneNumber) }) end) +RegisterNetEvent('esx_phone:removeContact') +AddEventHandler('esx_phone:removeContact', function(name, phoneNumber) + + for key, value in pairs(PhoneData.contacts) do + if value.name == name and value.number == phoneNumber then + table.remove(PhoneData.contacts,key) + end + end + -- CALL HERE RELOADCONTACT + SendNUIMessage({ + contactRemoved = true, + phoneData = PhoneData + }) +end) + RegisterNetEvent('esx_phone:addSpecialContact') AddEventHandler('esx_phone:addSpecialContact', function(name, phoneNumber, base64Icon) @@ -142,6 +157,16 @@ RegisterNUICallback('add_contact', function(data, cb) end) +RegisterNUICallback('remove_contact', function(data, cb) + + local phoneNumber = tonumber(data.phoneNumber) + local contactName = tostring(data.contactName) + + if phoneNumber then + TriggerServerEvent('esx_phone:removePlayerContact', phoneNumber, contactName) + end + +end) RegisterNetEvent('esx_phone:onMessage') AddEventHandler('esx_phone:onMessage', function(phoneNumber, message, position, anon, job, dispatchRequestId) diff --git a/html/css/app.css b/html/css/app.css index d29c0273..061b08e5 100644 --- a/html/css/app.css +++ b/html/css/app.css @@ -305,7 +305,7 @@ html, body { display: block; } -.actions .new-msg:hover, .actions .gps:hover, .actions .ok-btn:hover { +.actions .new-msg:hover, .actions .gps:hover, .actions .ok-btn:hover, .actions .del-contact:hover { background-color: #f1f1f1; } diff --git a/html/scripts/app.js b/html/scripts/app.js index 3afebe53..fd5c4835 100644 --- a/html/scripts/app.js +++ b/html/scripts/app.js @@ -7,7 +7,10 @@ '{{sender}}
#{{phoneNumber}}' + '' + '' + - '
' + + '
' + + 'X' + + '' + + '
' + '' ; @@ -119,6 +122,16 @@ } $('#phone #repertoire .repertoire-list').html(contactHTML); + + $('.contact .del-contact').click(function() { + let name = $(this).attr('data-contact-name'); + let phoneNumber = $(this).attr('data-contact-number'); + + $.post('http://esx_phone/remove_contact', JSON.stringify({ + contactName: name, + phoneNumber: phoneNumber + })) + }); $('.contact.online .new-msg').click(function() { showNewMessage($(this).attr('data-contact-number'), $(this).attr('data-contact-name')); @@ -451,6 +464,10 @@ hideAddContact(); } + if(data.contactRemoved === true){ + reloadPhone(data.phoneData); + } + if(data.addSpecialContact === true){ addSpecialContact(data.name, data.number, data.base64Icon); } diff --git a/locales/br.lua b/locales/br.lua index 600b3848..043754e2 100644 --- a/locales/br.lua +++ b/locales/br.lua @@ -7,5 +7,6 @@ Locales['br'] = { ['cannot_add_self'] = 'Você não pode se adicionar', ['number_in_contacts'] = 'Este número já está na sua lista de contatos', ['contact_added'] = 'Contato adicionado', + ['contact_removed'] = 'the contact has been removed!', ['number_not_assigned'] = 'Este número não foi atribuído...', } diff --git a/locales/de.lua b/locales/de.lua index 6216e74b..5f8606f7 100644 --- a/locales/de.lua +++ b/locales/de.lua @@ -7,5 +7,6 @@ Locales['de'] = { ['cannot_add_self'] = 'du kannst dich nicht selbst hinzufügen', ['number_in_contacts'] = 'diese Nummer ist bereits in deinen Kontakten', ['contact_added'] = 'Kontakt hinzugefügt', + ['contact_removed'] = 'the contact has been removed!', ['number_not_assigned'] = 'diese Nummer ist nicht vergeben...', } diff --git a/locales/en.lua b/locales/en.lua index 3d7f75df..b6d5c8b0 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -6,6 +6,8 @@ Locales['en'] = { ['message_sent'] = 'the message has been sent', ['cannot_add_self'] = 'you can not add yourself', ['number_in_contacts'] = 'this number is already in your contact list', + ['number_in_contacts'] = 'this number is already in your contact list', ['contact_added'] = 'the contact has been added!', + ['contact_removed'] = 'the contact has been removed!', ['number_not_assigned'] = 'this number is not assigned to anyone!', } diff --git a/locales/es.lua b/locales/es.lua index 68460324..af889ebf 100644 --- a/locales/es.lua +++ b/locales/es.lua @@ -7,5 +7,6 @@ Locales['es'] = { ['cannot_add_self'] = 'No has podido agregar', ['number_in_contacts'] = 'Este número ya está en tu lista de contactos', ['contact_added'] = 'Contacto añadido', + ['contact_removed'] = 'the contact has been removed!', ['number_not_assigned'] = 'El número no se ha añadido todavía...', } diff --git a/locales/fr.lua b/locales/fr.lua index bba0228e..ef6d2166 100644 --- a/locales/fr.lua +++ b/locales/fr.lua @@ -7,5 +7,6 @@ Locales['fr'] = { ['cannot_add_self'] = 'vous ne pouvez pas vous ajouter vous-même', ['number_in_contacts'] = 'ce numéro est déja dans votre liste de contacts', ['contact_added'] = 'contact ajouté', + ['contact_removed'] = 'contact supprimé', ['number_not_assigned'] = 'ce numéro n\'est pas attribué...', } diff --git a/server/main.lua b/server/main.lua index c5effb06..0c9a798b 100644 --- a/server/main.lua +++ b/server/main.lua @@ -248,7 +248,8 @@ AddEventHandler('esx_phone:addPlayerContact', function(phoneNumber, contactName) if foundNumber then - if phoneNumber == xPlayer.get('phoneNumber') then + -- if phoneNumber == xPlayer.get('phoneNumber') then + if false then TriggerClientEvent('esx:showNotification', _source, _U('cannot_add_self')) else @@ -299,6 +300,60 @@ AddEventHandler('esx_phone:addPlayerContact', function(phoneNumber, contactName) end) +RegisterServerEvent('esx_phone:removePlayerContact') +AddEventHandler('esx_phone:removePlayerContact', function(phoneNumber, contactName) + + local _source = source + local xPlayer = ESX.GetPlayerFromId(_source) + local foundNumber = false + local foundPlayer = nil + + MySQL.Async.fetchAll( + 'SELECT phone_number FROM users WHERE phone_number = @number', + { + ['@number'] = phoneNumber + }, + function(result) + + if result[1] ~= nil then + foundNumber = true + end + + if foundNumber then + + local contacts = xPlayer.get('contacts') + + for key, value in pairs(contacts) do + if value.name == contactName and value.number == phoneNumber then + table.remove(contacts,key) + end + end + + xPlayer.set('contacts', contacts) + + MySQL.Async.execute( + 'DELETE FROM user_contacts WHERE identifier=@identifier AND name=@name AND number=@number', + { + ['@identifier'] = xPlayer.identifier, + ['@name'] = contactName, + ['@number'] = phoneNumber + }, + function(rowsChanged) + + TriggerClientEvent('esx:showNotification', _source, _U('contact_removed')) + + TriggerClientEvent('esx_phone:removeContact', _source, contactName, phoneNumber) + end + ) + else + TriggerClientEvent('esx:showNotification', source, _U('number_not_assigned')) + end + + end + ) + +end) + RegisterServerEvent('esx_phone:stopDispatch') AddEventHandler('esx_phone:stopDispatch', function(dispatchRequestId) TriggerClientEvent('esx_phone:stopDispatch', -1, dispatchRequestId, GetPlayerName(source))