mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
Playing around with stuff
This commit is contained in:
1 parent
282e99df18
commit
04670233bc
9 files changed
+98
-37
No files matched your search
@@ -11,7 +11,7 @@ export const useEmail = () => {
|
|||||||
|
|
||||||
const [fetchInbox, { loading: inboxLoading }] = useNuiEventCallback(
|
const [fetchInbox, { loading: inboxLoading }] = useNuiEventCallback(
|
||||||
'EMAIL',
|
'EMAIL',
|
||||||
'phone:fetchEmails',
|
'phone:fetchInbox',
|
||||||
setInbox,
|
setInbox,
|
||||||
);
|
);
|
||||||
const [fetchSent, { loading: sentLoading }] = useNuiEventCallback(
|
const [fetchSent, { loading: sentLoading }] = useNuiEventCallback(
|
||||||
|
|||||||
@@ -26,11 +26,11 @@ InjectDebugData<IEmail[]>(
|
|||||||
data: [
|
data: [
|
||||||
{
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
|
subject: 'Hey!',
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
emailId: 1,
|
emailId: 1,
|
||||||
subject: 'Hey!',
|
|
||||||
body: 'Hey did you try this email app? Looking good bruh',
|
body: 'Hey did you try this email app? Looking good bruh',
|
||||||
receivers: ['[email protected]'],
|
receivers: ['[email protected]'],
|
||||||
sender: '[email protected]',
|
sender: '[email protected]',
|
||||||
@@ -40,11 +40,11 @@ InjectDebugData<IEmail[]>(
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 2,
|
id: 2,
|
||||||
|
subject: 'What is up?',
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
id: 2,
|
id: 2,
|
||||||
emailId: 2,
|
emailId: 2,
|
||||||
subject: 'What is up?',
|
|
||||||
body: 'Hey did you try this email app? Looking good bruh',
|
body: 'Hey did you try this email app? Looking good bruh',
|
||||||
receivers: ['[email protected]'],
|
receivers: ['[email protected]'],
|
||||||
sender: '[email protected]',
|
sender: '[email protected]',
|
||||||
@@ -60,12 +60,12 @@ InjectDebugData<IEmail[]>(
|
|||||||
data: [
|
data: [
|
||||||
{
|
{
|
||||||
id: 3,
|
id: 3,
|
||||||
|
subject: 'Try this great app! 1',
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
id: 11,
|
id: 11,
|
||||||
parentId: 12,
|
parentId: 12,
|
||||||
emailId: 3,
|
emailId: 3,
|
||||||
subject: 'Try this great app! 1',
|
|
||||||
body: 'Hey did you try this email app? Looking good bruh',
|
body: 'Hey did you try this email app? Looking good bruh',
|
||||||
receivers: ['[email protected]'],
|
receivers: ['[email protected]'],
|
||||||
sender: '[email protected]',
|
sender: '[email protected]',
|
||||||
@@ -77,7 +77,6 @@ InjectDebugData<IEmail[]>(
|
|||||||
id: 12,
|
id: 12,
|
||||||
parentId: 3,
|
parentId: 3,
|
||||||
emailId: 3,
|
emailId: 3,
|
||||||
subject: 'Try this great app! 2',
|
|
||||||
body: 'Hey did you try this email app? Looking good bruh',
|
body: 'Hey did you try this email app? Looking good bruh',
|
||||||
receivers: ['[email protected]'],
|
receivers: ['[email protected]'],
|
||||||
sender: '[email protected]',
|
sender: '[email protected]',
|
||||||
@@ -89,7 +88,6 @@ InjectDebugData<IEmail[]>(
|
|||||||
id: 3,
|
id: 3,
|
||||||
parentId: null,
|
parentId: null,
|
||||||
emailId: 3,
|
emailId: 3,
|
||||||
subject: 'Try this great app! 3',
|
|
||||||
body: 'Hey did you try this email app? Looking good bruh',
|
body: 'Hey did you try this email app? Looking good bruh',
|
||||||
receivers: ['[email protected]'],
|
receivers: ['[email protected]'],
|
||||||
sender: '[email protected]',
|
sender: '[email protected]',
|
||||||
@@ -101,11 +99,11 @@ InjectDebugData<IEmail[]>(
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 4,
|
id: 4,
|
||||||
|
subject: 'Try this great app!',
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
id: 4,
|
id: 4,
|
||||||
emailId: 1,
|
emailId: 1,
|
||||||
subject: 'Try this great app!',
|
|
||||||
body: 'Hey did you try this email app? Looking good bruh',
|
body: 'Hey did you try this email app? Looking good bruh',
|
||||||
receivers: ['[email protected]'],
|
receivers: ['[email protected]'],
|
||||||
sender: '[email protected]',
|
sender: '[email protected]',
|
||||||
@@ -116,11 +114,11 @@ InjectDebugData<IEmail[]>(
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 5,
|
id: 5,
|
||||||
|
subject: 'Try this great app!',
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
id: 5,
|
id: 5,
|
||||||
emailId: 5,
|
emailId: 5,
|
||||||
subject: 'Try this great app!',
|
|
||||||
body: 'Hey did you try this email app? Looking good bruh',
|
body: 'Hey did you try this email app? Looking good bruh',
|
||||||
receivers: ['[email protected]'],
|
receivers: ['[email protected]'],
|
||||||
sender: '[email protected]',
|
sender: '[email protected]',
|
||||||
@@ -131,11 +129,11 @@ InjectDebugData<IEmail[]>(
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 6,
|
id: 6,
|
||||||
|
subject: 'Try this great app!',
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
id: 6,
|
id: 6,
|
||||||
emailId: 6,
|
emailId: 6,
|
||||||
subject: 'Try this great app!',
|
|
||||||
body: 'Hey did you try this email app? Looking good bruh',
|
body: 'Hey did you try this email app? Looking good bruh',
|
||||||
receivers: ['[email protected]'],
|
receivers: ['[email protected]'],
|
||||||
sender: '[email protected]',
|
sender: '[email protected]',
|
||||||
@@ -146,11 +144,11 @@ InjectDebugData<IEmail[]>(
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 7,
|
id: 7,
|
||||||
|
subject: 'Try this great app!',
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
id: 7,
|
id: 7,
|
||||||
emailId: 7,
|
emailId: 7,
|
||||||
subject: 'Try this great app!',
|
|
||||||
body: 'Hey did you try this email app? Looking good bruh',
|
body: 'Hey did you try this email app? Looking good bruh',
|
||||||
receivers: ['[email protected]'],
|
receivers: ['[email protected]'],
|
||||||
sender: '[email protected]',
|
sender: '[email protected]',
|
||||||
@@ -161,11 +159,11 @@ InjectDebugData<IEmail[]>(
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 8,
|
id: 8,
|
||||||
|
subject: 'Try this great app!',
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
id: 8,
|
id: 8,
|
||||||
emailId: 8,
|
emailId: 8,
|
||||||
subject: 'Try this great app!',
|
|
||||||
body: 'Hey did you try this email app? Looking good bruh',
|
body: 'Hey did you try this email app? Looking good bruh',
|
||||||
receivers: ['[email protected]'],
|
receivers: ['[email protected]'],
|
||||||
sender: '[email protected]',
|
sender: '[email protected]',
|
||||||
@@ -176,11 +174,11 @@ InjectDebugData<IEmail[]>(
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 9,
|
id: 9,
|
||||||
|
subject: 'Try this great app!',
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
id: 9,
|
id: 9,
|
||||||
emailId: 9,
|
emailId: 9,
|
||||||
subject: 'Try this great app!',
|
|
||||||
body: 'Hey did you try this email app? Looking good bruh',
|
body: 'Hey did you try this email app? Looking good bruh',
|
||||||
receivers: ['[email protected]'],
|
receivers: ['[email protected]'],
|
||||||
sender: '[email protected]',
|
sender: '[email protected]',
|
||||||
@@ -191,11 +189,11 @@ InjectDebugData<IEmail[]>(
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 10,
|
id: 10,
|
||||||
|
subject: 'Try this great app!',
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
id: 10,
|
id: 10,
|
||||||
emailId: 10,
|
emailId: 10,
|
||||||
subject: 'Try this great app!',
|
|
||||||
body: 'Hey did you try this email app? Looking good bruh',
|
body: 'Hey did you try this email app? Looking good bruh',
|
||||||
receivers: ['[email protected]'],
|
receivers: ['[email protected]'],
|
||||||
sender: '[email protected]',
|
sender: '[email protected]',
|
||||||
|
|||||||
@@ -1,4 +1,66 @@
|
|||||||
import { ClUtils } from './client';
|
import { ClUtils } from './client';
|
||||||
import events from '../utils/events';
|
import events from '../utils/events';
|
||||||
|
import { uuidv4 } from 'fivem-js';
|
||||||
|
import { sendEmailEvent } from '../utils/messages';
|
||||||
|
import apps from '../utils/apps';
|
||||||
|
|
||||||
ClUtils.registerNuiServerCallback(events.EMAIL_FETCH_INBOX);
|
// ClUtils.registerNuiServerCallback(apps.EMAIL, events.EMAIL_FETCH_INBOX);
|
||||||
|
|
||||||
|
/* RegisterNuiCallbackType(events.EMAIL_FETCH_INBOX);
|
||||||
|
on(`__cfx_nui:${events.EMAIL_FETCH_INBOX}`, (data: any, cb: any) => {
|
||||||
|
console.log('wtf', data);
|
||||||
|
cb([]);
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
|
interface ICallback {
|
||||||
|
cb: (err: any, data?: unknown) => void;
|
||||||
|
timeout: NodeJS.Timeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
const event = events.EMAIL_FETCH_INBOX;
|
||||||
|
const _callbacks = new Map<string, ICallback>();
|
||||||
|
|
||||||
|
const uid = uuidv4();
|
||||||
|
const callbackId = `${event}:${uid}`;
|
||||||
|
|
||||||
|
RegisterNuiCallbackType(event);
|
||||||
|
on(`__cfx_nui:${event}`, (data: any, cb: (err: any, data?: any) => void) => {
|
||||||
|
if (_callbacks.has(callbackId)) {
|
||||||
|
cb(new Error(`Nui Server Callback with name "${event}" is already waiting for server!`));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
emitNet(event, data);
|
||||||
|
|
||||||
|
_callbacks.set(callbackId, {
|
||||||
|
cb,
|
||||||
|
timeout: setTimeout(() => {
|
||||||
|
if (_callbacks.has(callbackId)) {
|
||||||
|
_callbacks
|
||||||
|
.get(callbackId)
|
||||||
|
.cb(new Error(`Nui Server Callback with name "${event}" timed out`));
|
||||||
|
_callbacks.delete(callbackId);
|
||||||
|
}
|
||||||
|
}, 20000),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
onNet(`${event}Success`, (response: any) => {
|
||||||
|
if (_callbacks.has(callbackId)) {
|
||||||
|
const callback = _callbacks.get(callbackId);
|
||||||
|
clearTimeout(callback.timeout);
|
||||||
|
callback.cb(null, response);
|
||||||
|
_callbacks.delete(callbackId);
|
||||||
|
sendEmailEvent(`${event}Success`, response);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
onNet(`${event}Error`, (err: any) => {
|
||||||
|
if (_callbacks.has(callbackId)) {
|
||||||
|
const callback = _callbacks.get(callbackId);
|
||||||
|
clearTimeout(callback.timeout);
|
||||||
|
callback.cb(err);
|
||||||
|
_callbacks.delete(callbackId);
|
||||||
|
sendEmailEvent(`${event}Error`, err);
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import { uuidv4 } from '../utils/fivem';
|
import { uuidv4 } from '../utils/fivem';
|
||||||
|
import { sendMessage } from '../utils/messages';
|
||||||
|
|
||||||
interface ISettings {
|
interface ISettings {
|
||||||
promiseTimeout: number;
|
promiseTimeout: number;
|
||||||
@@ -59,51 +60,43 @@ export default class ClientUtils {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public registerNuiServerCallback<I = any, R = any>(event: string) {
|
public registerNuiServerCallback<I = any, R = any>(
|
||||||
RegisterNuiCallbackType(event);
|
app: string,
|
||||||
|
event: string,
|
||||||
|
successEvent?: string,
|
||||||
|
errorEvent?: string,
|
||||||
|
) {
|
||||||
const uid = uuidv4();
|
const uid = uuidv4();
|
||||||
const callbackId = `${event}:${uid}`;
|
const callbackId = `${event}:${uid}`;
|
||||||
|
|
||||||
|
RegisterNuiCallbackType(event);
|
||||||
on(`__cfx_nui:${event}`, (data: I, cb: (err: any, data?: R) => void) => {
|
on(`__cfx_nui:${event}`, (data: I, cb: (err: any, data?: R) => void) => {
|
||||||
if (this._callbacks.has(callbackId)) {
|
if (this._callbacks.has(callbackId)) {
|
||||||
cb(new Error(`Nui Server Callback with name "${event}" is already waiting for server!`));
|
cb(new Error(`Nui Server Callback with name "${event}" is already waiting for server!`));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
emitNet(event, data);
|
emitNet(event, data);
|
||||||
|
|
||||||
this._callbacks.set(callbackId, {
|
|
||||||
cb,
|
|
||||||
timeout: setTimeout(() => {
|
|
||||||
if (this._callbacks.has(callbackId)) {
|
|
||||||
this._callbacks
|
|
||||||
.get(callbackId)
|
|
||||||
.cb(
|
|
||||||
new Error(
|
|
||||||
`Nui Server Callback with name "${event}" timed out after ${this._settings.promiseTimeout}ms`,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
this._callbacks.delete(callbackId);
|
|
||||||
}
|
|
||||||
}, this._settings.promiseTimeout),
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
onNet(`${event}Success`, (response: R) => {
|
const _success = successEvent || `${event}Success`;
|
||||||
|
onNet(_success, (response: R) => {
|
||||||
if (this._callbacks.has(callbackId)) {
|
if (this._callbacks.has(callbackId)) {
|
||||||
const callback = this._callbacks.get(callbackId);
|
const callback = this._callbacks.get(callbackId);
|
||||||
clearTimeout(callback.timeout);
|
clearTimeout(callback.timeout);
|
||||||
callback.cb(null, response);
|
callback.cb(null, response);
|
||||||
this._callbacks.delete(callbackId);
|
this._callbacks.delete(callbackId);
|
||||||
|
sendMessage(app, _success, response);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
onNet(`${event}Error`, (err: any) => {
|
const _error = errorEvent || `${event}Error`;
|
||||||
|
onNet(_error, (err: any) => {
|
||||||
if (this._callbacks.has(callbackId)) {
|
if (this._callbacks.has(callbackId)) {
|
||||||
const callback = this._callbacks.get(callbackId);
|
const callback = this._callbacks.get(callbackId);
|
||||||
clearTimeout(callback.timeout);
|
clearTimeout(callback.timeout);
|
||||||
callback.cb(err);
|
callback.cb(err);
|
||||||
this._callbacks.delete(callbackId);
|
this._callbacks.delete(callbackId);
|
||||||
|
sendMessage(app, _error, err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import './cl_photo';
|
|||||||
import './cl_messages';
|
import './cl_messages';
|
||||||
import './cl_call';
|
import './cl_call';
|
||||||
import './cl_match';
|
import './cl_match';
|
||||||
|
import './cl_email';
|
||||||
import './functions';
|
import './functions';
|
||||||
|
|
||||||
export const ClUtils = new ClientUtils();
|
export const ClUtils = new ClientUtils();
|
||||||
@@ -11,6 +11,7 @@ import './sv_photo';
|
|||||||
import './sv_messages';
|
import './sv_messages';
|
||||||
import './sv_match';
|
import './sv_match';
|
||||||
import './sv_call';
|
import './sv_call';
|
||||||
|
import './sv_email';
|
||||||
import './players/sv_player_events';
|
import './players/sv_player_events';
|
||||||
import { mainLogger } from './sv_logger';
|
import { mainLogger } from './sv_logger';
|
||||||
|
|
||||||
|
|||||||
@@ -120,12 +120,13 @@ onNet(events.EMAIL_FETCH_INBOX, async () => {
|
|||||||
try {
|
try {
|
||||||
const email = '[email protected]';
|
const email = '[email protected]';
|
||||||
const messages = await fetchInbox(email);
|
const messages = await fetchInbox(email);
|
||||||
|
await new Promise((res) => setTimeout(res, 6000));
|
||||||
const inbox = getEmailsFromMessages(messages, email);
|
const inbox = getEmailsFromMessages(messages, email);
|
||||||
emitNet(events.EMAIL_FETCH_INBOX_SUCCESS, inbox);
|
emitNet(events.EMAIL_FETCH_INBOX_SUCCESS, _source, inbox);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emailLogger.error(`Failed to fetch email inbox, ${e.message}`, {
|
emailLogger.error(`Failed to fetch email inbox, ${e.message}`, {
|
||||||
source: _source,
|
source: _source,
|
||||||
});
|
});
|
||||||
emitNet(events.EMAIL_FETCH_INBOX_ERROR, e);
|
emitNet(events.EMAIL_FETCH_INBOX_ERROR, _source, e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
export default {
|
export default {
|
||||||
|
EMAIL: 'EMAIL',
|
||||||
TWITTER: 'TWITTER',
|
TWITTER: 'TWITTER',
|
||||||
MATCH: 'MATCH',
|
MATCH: 'MATCH',
|
||||||
MESSAGES: 'MESSAGES',
|
MESSAGES: 'MESSAGES',
|
||||||
|
|||||||
@@ -37,3 +37,7 @@ export function sendCameraEvent(method: string, data: any = {}) {
|
|||||||
export function sendMatchEvent(method: string, data: any = {}) {
|
export function sendMatchEvent(method: string, data: any = {}) {
|
||||||
return sendMessage(apps.MATCH, method, data);
|
return sendMessage(apps.MATCH, method, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function sendEmailEvent(method: string, data: any = {}) {
|
||||||
|
sendMessage(apps.EMAIL, method, data);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user