feat(calling): using unix as call time

This commit is contained in:
Christopher committed 2021-02-02 23:47:43 +01:00
1 parent 8ff9017902
commit e48864c6dc
10 files changed
+60 -24

No files matched your search

+1
View File
@@ -20,6 +20,7 @@
"@testing-library/user-event": "^7.2.1",
"@types/jest": "^26.0.14",
"core-js": "^3.6.5",
"dayjs": "^1.10.4",
"emoji-mart": "^3.0.0",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.5",
+2 -2
View File
@@ -65,12 +65,12 @@ if (process.env.NODE_ENV === 'development') {
{
id: 1,
transmitter: '636-6496',
transmitterName: 'Taso Weeb',
start: 1612301545782
},
{
id: 2,
transmitter: '777-7777',
transmitterName: 'Taso Weeb',
start: 1612301545782
},
],
},
@@ -8,12 +8,16 @@ import Nui from '../../../../os/nui-events/utils/Nui'
import { useSimcard } from '../../../../os/simcard/hooks/useSimcard';
import { useContacts } from '../../../contacts/hooks/useContacts';
import { ICall } from '../../../../common/typings/call';
import dayjs from 'dayjs'
import { useTranslation } from 'react-i18next';
export const DialerHistory = ({ calls }) => {
const { number } = useSimcard();
const { getDisplayByNumber } = useContacts();
const { t } = useTranslation()
const handleCall = (phoneNumber) => {
Nui.send('phone:beginCall', {
number: phoneNumber
@@ -28,12 +32,12 @@ export const DialerHistory = ({ calls }) => {
<List disablePadding>
{calls.map((call: ICall) => call.transmitter === number ? (
<ListItem key={call.id} divider button onClick={() => handleCall(call.receiver)}>
<ListItemText primary={getDisplayByNumber(call.receiver)} secondary={call.timestamp} />
<ListItemText primary={getDisplayByNumber(call.receiver)} secondary={new Date(call.start).getUTCDate()}/>
{<PhoneForwardedIcon />}
</ListItem>
): (
<ListItem key={call.id} divider button onClick={() => handleCall(call.transmitter)}>
<ListItemText primary={getDisplayByNumber(call.transmitter)} secondary={call.timestamp} />
<ListItemText primary={getDisplayByNumber(call.transmitter)} secondary={dayjs.unix(call.start).format(t("DATE_TIME_FORMAT"))} />
{<PhoneCallbackIcon />}
</ListItem>
))}
+3 -1
View File
@@ -7,11 +7,13 @@ export interface CallProps {
export interface ICall {
id?: number;
identifier: string;
transmitter: string;
transmitterSource?: number;
receiver: string;
receiverSource?: number;
timestamp: string;
start: number;
end?: number;
}
export interface ICallDuration {
+3
View File
@@ -1,5 +1,8 @@
{
"translation": {
"DATE_FORMAT": "MM/DD/YYYY",
"DATE_TIME_FORMAT": "MM/DD/YYYY hh:mm A",
"COMING_SOON": "Coming soon...",
"APPS_DIALER": "Phone",
"APPS_CONTACTS": "Contacts",
+5
View File
@@ -4241,6 +4241,11 @@ data-urls@^1.0.0, data-urls@^1.1.0:
whatwg-mimetype "^2.2.0"
whatwg-url "^7.0.0"
dayjs@^1.10.4:
version "1.10.4"
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.10.4.tgz#8e544a9b8683f61783f570980a8a80eaf54ab1e2"
integrity sha512-RI/Hh4kqRc1UKLOAf/T5zdMMX5DQIlDxwUe3wSyMMnEbGunnpENCdbUgM+dW7kXidZqCttBrmw7BhN4TMddkCw==
[email protected], debug@^2.2.0, debug@^2.3.3, debug@^2.6.0, debug@^2.6.9:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
+6 -8
View File
@@ -1,17 +1,13 @@
import { ESX } from './client';
import events from '../utils/events';
import { ICall } from '../../phone/src/common/typings/call';
import config from '../utils/config';
import dayjs from 'dayjs';
const exp = (global as any).exports;
RegisterNuiCallbackType(events.PHONE_INITIALIZE_CALL);
on(`__cfx_nui:${events.PHONE_INITIALIZE_CALL}`, (data: any) => {
const timestamp = dayjs().locale(config.Locale).format('HH:mm');
const start = Date.now();
const start = Date.now()
emitNet(events.PHONE_INITIALIZE_CALL, data.number, timestamp, start);
emitNet(events.PHONE_INITIALIZE_CALL, data.number, start);
});
onNet(
@@ -61,7 +57,8 @@ onNet(
RegisterNuiCallbackType(events.PHONE_CALL_REJECTED);
on(`__cfx_nui:${events.PHONE_CALL_REJECTED}`, (data: any) => {
emitNet(events.PHONE_CALL_REJECTED, data.transmitterNumber);
const end = Date.now()
emitNet(events.PHONE_CALL_REJECTED, data.transmitterNumber, end);
});
onNet(events.PHONE_CALL_WAS_REJECTED, () => {
@@ -83,7 +80,8 @@ onNet(events.PHONE_CALL_WAS_REJECTED, () => {
RegisterNuiCallbackType(events.PHONE_END_CALL);
on(`__cfx_nui:${events.PHONE_END_CALL}`, (data: any) => {
emitNet(events.PHONE_END_CALL, data.transmitterNumber);
const end = Date.now()
emitNet(events.PHONE_END_CALL, data.transmitterNumber, end);
});
onNet(events.PHONE_CALL_WAS_ENDED, () => {
+3 -1
View File
@@ -17,6 +17,7 @@
"@citizenfx/client": "^1.0.2792-1",
"@citizenfx/server": "^1.0.2792-1",
"@types/node": "^14.11.10",
"@types/uuid": "^8.3.0",
"axios": "^0.21.0",
"connection-string-parser": "^1.0.3",
"dayjs": "^1.10.4",
@@ -24,7 +25,8 @@
"fivem-esx-js": "^0.1.12",
"fivem-js": "^1.3.1",
"md5": "^2.3.0",
"mysql2": "^2.2.5"
"mysql2": "^2.2.5",
"uuid": "^8.3.2"
},
"devDependencies": {
"@babel/preset-env": "^7.12.1",
+25 -9
View File
@@ -9,6 +9,9 @@ import { XPlayer } from 'esx.js/@types/server';
import { ICall } from '../../phone/src/common/typings/call';
import { pool } from './db';
import { v4 as uuidv4} from 'uuid';
import { ConnectionStringParser } from 'connection-string-parser';
import { time } from 'console';
/**
* Returns the player phoneNumber for a passed identifier
@@ -32,17 +35,20 @@ async function getPlayerFromIdentifier(identifier: string): Promise<XPlayer> {
});
}
async function saveCall(call: ICall) {
const query =
'INSERT INTO npwd_calls (transmitter, receiver, timestamp) VALUES (?, ?, ?)';
await pool.query(query, [call.transmitter, call.receiver, call.timestamp]);
'INSERT INTO npwd_calls (transmitter, receiver, start) VALUES (?, ?, ?)';
await pool.query(query, [call.transmitter, call.receiver, call.start]);
}
async function updateCall(call: ICall, isAccepted: boolean) {
const query = 'UPDATE npwd_calls SET is_accepted (?) WHERE transmitter = ?';
await pool.query(query, [isAccepted, call.transmitter]);
async function updateCall(call: ICall, isAccepted: boolean, end?: number) {
const query = 'UPDATE npwd_calls SET is_accepted, end (?, ?) WHERE identifier = ?';
await pool.query(query, [isAccepted, end, call.identifier]);
}
async function fetchCalls(phoneNumber: string): Promise<ICall[]> {
const query =
'SELECT * FROM npwd_calls WHERE receiver = ? OR transmitter = ?';
@@ -51,13 +57,17 @@ async function fetchCalls(phoneNumber: string): Promise<ICall[]> {
return calls;
}
let calls: Map<string, ICall> = new Map();
onNet(
events.PHONE_INITIALIZE_CALL,
async (phoneNumber: string, timestamp: string) => {
async (phoneNumber: string, timestamp: number) => {
const _source = (global as any).source;
const callIdentifier = uuidv4();
// the client that is calling
const xTransmitter = ESX.GetPlayerFromId(_source);
const transmitterNumber = await usePhoneNumber(
@@ -70,11 +80,12 @@ onNet(
const receiverNumber = phoneNumber;
calls.set(transmitterNumber, {
identifier: callIdentifier,
transmitter: transmitterNumber,
transmitterSource: _source,
receiver: receiverNumber,
receiverSource: xReceiver.source,
timestamp: timestamp,
start: timestamp / 1000,
});
const currentCall = calls.get(transmitterNumber);
@@ -132,11 +143,12 @@ onNet(events.PHONE_ACCEPT_CALL, async (transmitterNumber: string) => {
}
});
onNet(events.PHONE_CALL_REJECTED, (transmitterNumber: string) => {
onNet(events.PHONE_CALL_REJECTED, async (transmitterNumber: string, timestamp: number) => {
try {
const pSource = (global as any).source;
const currentCall = calls.get(transmitterNumber);
await updateCall(currentCall, false, timestamp)
// player who is being called
emitNet(events.PHONE_CALL_WAS_REJECTED, pSource);
@@ -147,11 +159,15 @@ onNet(events.PHONE_CALL_REJECTED, (transmitterNumber: string) => {
}
});
onNet(events.PHONE_END_CALL, async (transmitterNumber: string) => {
onNet(events.PHONE_END_CALL, async (transmitterNumber: string, timestamp: number) => {
try {
const pSource = (global as any).source;
const currentCall = calls.get(transmitterNumber);
const endTime = timestamp / 1000;
await updateCall(currentCall, false, endTime)
// player who is being called
emitNet(events.PHONE_CALL_WAS_ENDED, currentCall.receiverSource);
// player who is calling
+6 -1
View File
@@ -1299,6 +1299,11 @@
dependencies:
source-map "^0.6.1"
"@types/uuid@^8.3.0":
version "8.3.0"
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.0.tgz#215c231dff736d5ba92410e6d602050cce7e273f"
integrity sha512-eQ9qFW/fhfGJF8WKHGEHZEyVWfZxrT+6CLIJGBcZPfxUh/+BnEj+UCGYMlr9qZuX/2AltsvwrGqp0LhEW8D0zQ==
"@types/webpack-sources@*":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@types/webpack-sources/-/webpack-sources-2.0.0.tgz#08216ab9be2be2e1499beaebc4d469cec81e82a7"
@@ -6910,7 +6915,7 @@ uuid@^3.3.2:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==
uuid@^8.3.0:
uuid@^8.3.0, uuid@^8.3.2:
version "8.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==