diff --git a/apps/game/client/cl_contacts.ts b/apps/game/client/cl_contacts.ts index 991e151cb..4644e323f 100644 --- a/apps/game/client/cl_contacts.ts +++ b/apps/game/client/cl_contacts.ts @@ -1,8 +1,16 @@ import { ContactEvents } from '@typings/contact'; import { RegisterNuiProxy } from './cl_utils'; +import { sendContactsEvent } from "../utils/messages"; RegisterNuiProxy(ContactEvents.PAY_CONTACT); RegisterNuiProxy(ContactEvents.GET_CONTACTS); RegisterNuiProxy(ContactEvents.ADD_CONTACT); RegisterNuiProxy(ContactEvents.DELETE_CONTACT); RegisterNuiProxy(ContactEvents.UPDATE_CONTACT); +RegisterNuiProxy(ContactEvents.LOCAL_SHARE) + +const exp = global.exports + +onNet("npwd:contacts:receiveContact", (data: unknown) => { + sendContactsEvent(ContactEvents.ADD_CONTACT_EXPORT, data); +}) \ No newline at end of file diff --git a/apps/game/server/contacts/contacts.controller.ts b/apps/game/server/contacts/contacts.controller.ts index db82be4a8..e985a3f1e 100644 --- a/apps/game/server/contacts/contacts.controller.ts +++ b/apps/game/server/contacts/contacts.controller.ts @@ -4,6 +4,7 @@ import PlayerService from '../players/player.service'; import ContactService from './contacts.service'; import { contactsLogger } from './contacts.utils'; import { onNetPromise } from '../lib/PromiseNetEvents/onNetPromise'; +import { distanceBetweenCoords } from "../utils/miscUtils"; const exps = global.exports; onNetPromise(ContactEvents.PAY_CONTACT, (reqObj, resp) => { @@ -60,3 +61,9 @@ onNetPromise(ContactEvents.DELETE_CONTACT, (reqObj, resp resp({ status: 'error', errorMsg: 'INTERNAL_ERROR' }); }); }); + +onNetPromise(ContactEvents.LOCAL_SHARE, (reqObj, resp) => { + ContactService.handleLocalShare(reqObj, resp).catch((e) => { + resp({status: 'error', errorMsg: 'INTERNAL_ERROR'}) + }) +}) \ No newline at end of file diff --git a/apps/game/server/contacts/contacts.service.ts b/apps/game/server/contacts/contacts.service.ts index 0ec797e57..e0dba9a16 100644 --- a/apps/game/server/contacts/contacts.service.ts +++ b/apps/game/server/contacts/contacts.service.ts @@ -4,6 +4,8 @@ import { Contact, ContactDeleteDTO, ContactResp, PreDBContact } from '@typings/c import { PromiseEventResp, PromiseRequest } from '../lib/PromiseNetEvents/promise.types'; import { checkAndFilterImage } from './../utils/imageFiltering'; import { _ContactsDB, ContactsDB } from './contacts.database'; +import { distanceBetweenCoords } from "../utils/miscUtils"; +import { generateProfileName } from "../utils/generateProfileName"; class _ContactService { private readonly contactsDB: _ContactsDB; @@ -76,6 +78,29 @@ class _ContactService { contactsLogger.error(`Error in handleFetchContact (${identifier}), ${e.message}`); } } + + async handleLocalShare( + reqObj: PromiseRequest, + resp: PromiseEventResp + ): Promise { + const source = reqObj.source.toString() + const sourceCoords = GetEntityCoords(GetPlayerPed(source)) + + const player = PlayerService.getPlayer(reqObj.source) + const name = player.getName() + const number = player.getPhoneNumber() + + getPlayers()?.forEach(src => { + if (src === source) return; + + const dist = distanceBetweenCoords(sourceCoords, GetEntityCoords(GetPlayerPed(src))) + if (dist <=3 ){ + emitNet('npwd:contacts:receiveContact', src, {name, number}) + } + }) + + resp({status: "ok"}) + } } const ContactService = new _ContactService(); diff --git a/apps/game/server/utils/miscUtils.ts b/apps/game/server/utils/miscUtils.ts index bb8640925..b14e3ae9d 100644 --- a/apps/game/server/utils/miscUtils.ts +++ b/apps/game/server/utils/miscUtils.ts @@ -18,3 +18,13 @@ export const emitNetTyped = (eventName: string, data: T, src?: number) emitNet(eventName, data); }; + +export const distanceBetweenCoords = (coords1: number[], coords2: number[]): number => { + const [x1,y1] = coords1 + const [x2, y2] = coords2 + + return Math.sqrt( + Math.pow((x2-x1), 2) + + Math.pow((y2-y1), 2) + ) +} diff --git a/apps/phone/src/apps/contacts/components/List/ContactList.tsx b/apps/phone/src/apps/contacts/components/List/ContactList.tsx index b160f6094..7f787dbef 100644 --- a/apps/phone/src/apps/contacts/components/List/ContactList.tsx +++ b/apps/phone/src/apps/contacts/components/List/ContactList.tsx @@ -2,16 +2,22 @@ import React from 'react'; import { SearchContacts } from './SearchContacts'; import { Link, useHistory, useLocation } from 'react-router-dom'; import { useFilteredContacts } from '../../hooks/state'; -import { Contact } from '@typings/contact'; +import { Contact, ContactEvents } from "@typings/contact"; import { useCall } from '@os/call/hooks/useCall'; import useMessages from '@apps/messages/hooks/useMessages'; import LogDebugEvent from '@os/debug/LogDebugEvents'; import { useContactActions } from '@apps/contacts/hooks/useContactActions'; import { useMyPhoneNumber } from '@os/simcard/hooks/useMyPhoneNumber'; -import { Phone, MessageSquare, Plus } from 'lucide-react'; +import { Phone, MessageSquare, Plus, Clipboard, UsersRound } from 'lucide-react'; import { List, ListItem, NPWDButton } from '@npwd/keyos'; import { initials } from '@utils/misc'; import { useQueryParams } from '@common/hooks/useQueryParams'; +import { Tooltip } from '@ui/components/Tooltip'; +import { useTwitterProfileValue } from "@apps/twitter/hooks/state"; +import { useTranslation } from "react-i18next"; +import { setClipboard } from "@os/phone/hooks"; +import { useSnackbar } from '@os/snackbar/hooks/useSnackbar'; +import fetchNui from "@utils/fetchNui"; export const ContactList: React.FC = () => { const filteredContacts = useFilteredContacts(); @@ -26,6 +32,9 @@ export const ContactList: React.FC = () => { return r; }, []); + const myNumber = useMyPhoneNumber() + const {avatar_url} = useTwitterProfileValue() + return (
@@ -44,6 +53,12 @@ export const ContactList: React.FC = () => {