Skip to content

Commit

Permalink
affichage rues proches sms
Browse files Browse the repository at this point in the history
  • Loading branch information
Kedrihan committed Jul 15, 2024
1 parent d2cb866 commit fd887d9
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 17 deletions.
18 changes: 14 additions & 4 deletions resources/[soz]/soz-phone/src/client/cl_messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,29 @@ RegisterNuiCB<void>(MessageEvents.DELETE_WAYPOINT, async (any, cb) => {
});

RegisterNuiCB<void>(MessageEvents.GET_POSITION, async (position: any, cb) => {
const [posX, posY] = GetEntityCoords(PlayerPedId(), true);
cb({ data: { x: posX, y: posY } });
const [posX, posY, posZ] = GetEntityCoords(PlayerPedId(), true);
cb({ data: { x: posX, y: posY, z: posZ } });
});

RegisterNuiCB<void>(MessageEvents.GET_DESTINATION, async (position: any, cb) => {
const [posX, posY] = GetBlipInfoIdCoord(GetFirstBlipInfoId(8));
cb({ data: { x: posX, y: posY } });
const [posX, posY, posZ] = GetBlipInfoIdCoord(GetFirstBlipInfoId(8));
cb({ data: { x: posX, y: posY, z: posZ } });
});

RegisterNuiCB<void>(SocietyEvents.SEND_CLIENT_POLICE_NOTIFICATION, async (message: any, cb) => {
cb(exports['soz-core'].SendPoliceNotification(message));
});

RegisterNuiCB<void>(MessageEvents.GET_STREET_NAME, async (position: any, cb) => {
const [streetA, streetB] = GetStreetNameAtCoord(Number(position.x), Number(position.y), Number(position.z));
var street = `${GetStreetNameFromHashKey(streetA)}`;

if (streetB && streetA !== streetB) {
street += ` & ${GetStreetNameFromHashKey(streetB)}`;
}
cb({ data: street });
});

onNet(MessageEvents.SEND_MESSAGE_SUCCESS, (messageDto: PreDBMessage) => {
sendMessageEvent(MessageEvents.SEND_MESSAGE_SUCCESS, messageDto);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,59 @@ import { setClipboard } from '../../../../os/phone/hooks/useClipboard';
import Emoji from '../../../../ui/components/Emoji';
import { Button } from '../../../../ui/old_components/Button';

const isImage = url => {
const isImage = (url) => {
return /(http(s?):)([/|.|\w|\s|-])*\.(?:jpg|png|jpeg|gif)/g.test(url);
};

const isPosition = url => {
const isOldPosition = (url) => {
return /vec2\((-?[0-9.]+),(-?[0-9.]+)\)/g.test(url);
};

const isPosition = (url) => {
return /vec3\((-?[0-9.]+),(-?[0-9.]+),(-?[0-9.]+)\)/g.test(url);
};

const getAddress = async (input: string) => {
const position = /vec3\((-?[0-9.]+),(-?[0-9.]+),(-?[0-9.]+)\)/g.exec(input);
const street_name = await fetchNui(MessageEvents.GET_STREET_NAME, {
x: position[1],
y: position[2],
z: position[3],
});
return street_name.data;
};

interface MessageBubbleProps {
message: Message;
}

export const MessageBubble: React.FC<MessageBubbleProps> = ({ message }) => {
const config = useConfig();
const myNumber = usePhoneNumber();

const [address, setAddress] = React.useState('');
const setWaypoint = () => {
const position = /vec2\((-?[0-9.]+),(-?[0-9.]+)\)/g.exec(message.message);
const position = /vec3\((-?[0-9.]+),(-?[0-9.]+),(-?[0-9.]+)\)/g.exec(message.message);
const oldPosition = /vec2\((-?[0-9.]+),(-?[0-9.]+)\)/g.exec(message.message);

fetchNui<ServerPromiseResp<void>>(MessageEvents.SET_WAYPOINT, {
x: position[1],
y: position[2],
x: position ? position[1] : oldPosition[1],
y: position ? position[2] : oldPosition[2],
});
};
React.useEffect(() => {
const getAddressAsync = async () => {
try {
const address = await getAddress(message.message);
setAddress(address);
} catch (error) {
console.error(error);
setAddress('Destination');
}
};
if (isPosition(message.message)) {
getAddressAsync();
}
}, [message.message]);

const isMine = message.author === myNumber;

Expand All @@ -63,11 +92,16 @@ export const MessageBubble: React.FC<MessageBubbleProps> = ({ message }) => {
</PictureReveal>
)}
{isPosition(message.message) && (
<span className="flex items-center cursor-pointer" onClick={setWaypoint}>
<LocationMarkerIcon className="h-5 w-5 mr-2" /> {address}
</span>
)}
{isOldPosition(message.message) && (
<span className="flex items-center cursor-pointer" onClick={setWaypoint}>
<LocationMarkerIcon className="h-5 w-5 mr-2" /> Destination
</span>
)}
{!isImage(message.message) && !isPosition(message.message) && (
{!isImage(message.message) && !isPosition(message.message) && !isOldPosition(message.message) && (
<Menu.Button className="left-0 h-full w-full text-left">
<p
className={cn('break-words text-ellipsis w-full select-text whitespace-pre-wrap', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const MessageImageModal = ({ isOpen, messageGroupId, onClose, image }: IP
fetchNui<ServerPromiseResp<any>>(MessageEvents.GET_POSITION, {}).then(resp => {
sendMessage({
conversationId: messageGroupId,
message: `vec2(${resp.data.x},${resp.data.y})`,
message: `vec3(${resp.data.x},${resp.data.y},${resp.data.z})`,
});
onClose();
});
Expand All @@ -78,7 +78,7 @@ export const MessageImageModal = ({ isOpen, messageGroupId, onClose, image }: IP
if (resp.data.x !== 0 && resp.data.y !== 0) {
sendMessage({
conversationId: messageGroupId,
message: `vec2(${resp.data.x},${resp.data.y})`,
message: `vec3(${resp.data.x},${resp.data.y},${resp.data.z})`,
});
onClose();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,40 @@ import React from 'react';

import { useEmergency } from '../../../../nui/hooks/useEmergency';
import { useNotifications } from '../hooks/useNotifications';
import { MessageEvents } from '@typings/messages';
import { fetchNui } from '@utils/fetchNui';

const getAddress = async (input: string) => {
const position = /vec3\((-?[0-9.]+),(-?[0-9.]+),(-?[0-9.]+)\)/g.exec(input);
const street_name = await fetchNui(MessageEvents.GET_STREET_NAME, {
x: position[1],
y: position[2],
z: position[3],
});
return street_name.data;
};

export const NotificationAlert = () => {
const { currentAlert } = useNotifications();
const emergency = useEmergency();

const [address, setAddress] = React.useState('');
// TODO: improve notification hook
const isPosition = /vec2\((-?[\d.]+),(-?[\d.]+)\)/g.test(currentAlert?.content.toString());
const isOldPosition = /vec2\((-?[\d.]+),(-?[\d.]+)\)/g.test(currentAlert?.content.toString());
const isPosition = /vec3\((-?[\d.]+),(-?[\d.]+),(-?[\d.]+)\)/g.test(currentAlert?.content.toString());
React.useEffect(() => {
const getAddressAsync = async () => {
try {
const address = await getAddress(currentAlert?.content.toString());
setAddress(address);
} catch (error) {
console.error(error);
setAddress('Destination');
}
};
if (isPosition) {
getAddressAsync();
}
}, [currentAlert?.content.toString()]);

if (!currentAlert || emergency) {
return null;
Expand All @@ -28,8 +55,8 @@ export const NotificationAlert = () => {
leaveFrom="translate-y-0"
leaveTo="-translate-y-full"
>
<Alert onClick={e => currentAlert?.onClickAlert(e)} icon={currentAlert?.notificationIcon || undefined}>
{isPosition ? 'Destination' : currentAlert?.content}
<Alert onClick={(e) => currentAlert?.onClickAlert(e)} icon={currentAlert?.notificationIcon || undefined}>
{isPosition ? address : isOldPosition ? 'Destination' : currentAlert?.content}
</Alert>
</Transition>
);
Expand Down
1 change: 1 addition & 0 deletions resources/[soz]/soz-phone/typings/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,5 @@ export enum MessageEvents {
SET_WAYPOINT = 'phone:setWaypoint',
DELETE_WAYPOINT = 'phone:deleteWaypoint',
SET_CONVERSATION_ARCHIVED = 'phone:setConversationArchived',
GET_STREET_NAME = 'phone:getStreetName',
}

0 comments on commit fd887d9

Please sign in to comment.