feat(calling/client|server): handling timestamps for calls

This commit is contained in:
Christopher committed 2021-01-31 02:46:33 +01:00
1 parent da4592d531
commit 342fd9aaba
2 files changed
+17 -9

No files matched your search

+4 -1
View File
@@ -1,12 +1,15 @@
import { ESX } from './client'; import { ESX } from './client';
import events from '../utils/events'; import events from '../utils/events';
import { ICall, ICallUI } from '../../phone/src/common/typings/call'; import { ICall, ICallUI } from '../../phone/src/common/typings/call';
import config from '../utils/config'
import dayjs from 'dayjs';
const exp = (global as any).exports; const exp = (global as any).exports;
RegisterNuiCallbackType(events.PHONE_INITIALIZE_CALL); RegisterNuiCallbackType(events.PHONE_INITIALIZE_CALL);
on(`__cfx_nui:${events.PHONE_INITIALIZE_CALL}`, (data: any) => { on(`__cfx_nui:${events.PHONE_INITIALIZE_CALL}`, (data: any) => {
emitNet(events.PHONE_INITIALIZE_CALL, data.number); const timestamp = dayjs().locale(config.Locale).format('HH:mm')
emitNet(events.PHONE_INITIALIZE_CALL, data.number, timestamp);
}); });
onNet( onNet(
+13 -8
View File
@@ -9,6 +9,7 @@ import { XPlayer } from 'esx.js/@types/server';
import { ICall, ICallUI } from '../../phone/src/common/typings/call'; import { ICall, ICallUI } from '../../phone/src/common/typings/call';
import { pool } from './db'; import { pool } from './db';
import { time } from 'console';
/** /**
* Returns the player phoneNumber for a passed identifier * Returns the player phoneNumber for a passed identifier
@@ -32,14 +33,14 @@ async function getPlayerFromIdentifier(identifier: string): Promise<XPlayer> {
}); });
} }
async function saveCall(call: ICall, isAccepted: boolean) { async function saveCall(call: ICall) {
const query = const query =
'INSERT INTO npwd_calls (transmitter, receiver, accepted, is_caller) VALUES (?, ?)'; 'INSERT INTO npwd_calls (transmitter, receiver, timestamp) VALUES (?, ?, ?)';
await pool.query(query, [call.transmitter, call.receiver, isAccepted]); await pool.query(query, [call.transmitter, call.receiver, call.timestamp]);
} }
async function updateCall(call: ICall, isAccepted: boolean) { async function updateCall(call: ICall, isAccepted: boolean) {
const query = 'UPDATE npwd_calls SET is_accepted (?) WHERE trasmitter = ?'; const query = 'UPDATE npwd_calls SET is_accepted (?) WHERE transmitter = ?';
await pool.query(query, [isAccepted, call.transmitter]); await pool.query(query, [isAccepted, call.transmitter]);
} }
@@ -53,7 +54,7 @@ async function fetchCalls(phoneNumber: string): Promise<ICallUI[]> {
let calls: Map<string, ICall> = new Map(); let calls: Map<string, ICall> = new Map();
onNet(events.PHONE_INITIALIZE_CALL, async (phoneNumber: string) => { onNet(events.PHONE_INITIALIZE_CALL, async (phoneNumber: string, timestamp: string) => {
const _source = (global as any).source; const _source = (global as any).source;
// the client that is calling // the client that is calling
@@ -70,8 +71,13 @@ onNet(events.PHONE_INITIALIZE_CALL, async (phoneNumber: string) => {
transmitterSource: _source, transmitterSource: _source,
receiver: receiverNumber, receiver: receiverNumber,
receiverSource: xReceiver.source, receiverSource: xReceiver.source,
timestamp: timestamp
}); });
const currentCall = calls.get(transmitterNumber);
await saveCall(currentCall)
// events // events
// client that is calling // client that is calling
emitNet( emitNet(
@@ -92,6 +98,7 @@ onNet(events.PHONE_INITIALIZE_CALL, async (phoneNumber: string) => {
); );
}); });
onNet(events.PHONE_ACCEPT_CALL, async (transmitterNumber: string) => { onNet(events.PHONE_ACCEPT_CALL, async (transmitterNumber: string) => {
try { try {
const pSource = (global as any).source; const pSource = (global as any).source;
@@ -109,9 +116,7 @@ onNet(events.PHONE_ACCEPT_CALL, async (transmitterNumber: string) => {
); );
// player who is calling // player who is calling
await updateCall(currentCall, true);
emitNet( emitNet(
events.PHONE_CALL_WAS_ACCEPTED, events.PHONE_CALL_WAS_ACCEPTED,
currentCall.transmitterSource, currentCall.transmitterSource,