Playing around with stuff

This commit is contained in:
J Francisco Rader authored and J Francisco Rader committed 2021-03-30 02:07:56 -03:00
1 parent 282e99df18
commit 04670233bc
9 files changed
+98 -37

No files matched your search

+1 -1
View File
@@ -11,7 +11,7 @@ export const useEmail = () => {
const [fetchInbox, { loading: inboxLoading }] = useNuiEventCallback(
'EMAIL',
'phone:fetchEmails',
'phone:fetchInbox',
setInbox,
);
const [fetchSent, { loading: sentLoading }] = useNuiEventCallback(
+10 -12
View File
@@ -26,11 +26,11 @@ InjectDebugData<IEmail[]>(
data: [
{
id: 1,
subject: 'Hey!',
messages: [
{
id: 1,
emailId: 1,
subject: 'Hey!',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
@@ -40,11 +40,11 @@ InjectDebugData<IEmail[]>(
},
{
id: 2,
subject: 'What is up?',
messages: [
{
id: 2,
emailId: 2,
subject: 'What is up?',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
@@ -60,12 +60,12 @@ InjectDebugData<IEmail[]>(
data: [
{
id: 3,
subject: 'Try this great app! 1',
messages: [
{
id: 11,
parentId: 12,
emailId: 3,
subject: 'Try this great app! 1',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
@@ -77,7 +77,6 @@ InjectDebugData<IEmail[]>(
id: 12,
parentId: 3,
emailId: 3,
subject: 'Try this great app! 2',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
@@ -89,7 +88,6 @@ InjectDebugData<IEmail[]>(
id: 3,
parentId: null,
emailId: 3,
subject: 'Try this great app! 3',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
@@ -101,11 +99,11 @@ InjectDebugData<IEmail[]>(
},
{
id: 4,
subject: 'Try this great app!',
messages: [
{
id: 4,
emailId: 1,
subject: 'Try this great app!',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
@@ -116,11 +114,11 @@ InjectDebugData<IEmail[]>(
},
{
id: 5,
subject: 'Try this great app!',
messages: [
{
id: 5,
emailId: 5,
subject: 'Try this great app!',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
@@ -131,11 +129,11 @@ InjectDebugData<IEmail[]>(
},
{
id: 6,
subject: 'Try this great app!',
messages: [
{
id: 6,
emailId: 6,
subject: 'Try this great app!',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
@@ -146,11 +144,11 @@ InjectDebugData<IEmail[]>(
},
{
id: 7,
subject: 'Try this great app!',
messages: [
{
id: 7,
emailId: 7,
subject: 'Try this great app!',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
@@ -161,11 +159,11 @@ InjectDebugData<IEmail[]>(
},
{
id: 8,
subject: 'Try this great app!',
messages: [
{
id: 8,
emailId: 8,
subject: 'Try this great app!',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
@@ -176,11 +174,11 @@ InjectDebugData<IEmail[]>(
},
{
id: 9,
subject: 'Try this great app!',
messages: [
{
id: 9,
emailId: 9,
subject: 'Try this great app!',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
@@ -191,11 +189,11 @@ InjectDebugData<IEmail[]>(
},
{
id: 10,
subject: 'Try this great app!',
messages: [
{
id: 10,
emailId: 10,
subject: 'Try this great app!',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
+63 -1
View File
@@ -1,4 +1,66 @@
import { ClUtils } from './client';
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);
}
});
+14 -21
View File
@@ -1,4 +1,5 @@
import { uuidv4 } from '../utils/fivem';
import { sendMessage } from '../utils/messages';
interface ISettings {
promiseTimeout: number;
@@ -59,51 +60,43 @@ export default class ClientUtils {
});
}
public registerNuiServerCallback<I = any, R = any>(event: string) {
RegisterNuiCallbackType(event);
public registerNuiServerCallback<I = any, R = any>(
app: string,
event: string,
successEvent?: string,
errorEvent?: string,
) {
const uid = uuidv4();
const callbackId = `${event}:${uid}`;
RegisterNuiCallbackType(event);
on(`__cfx_nui:${event}`, (data: I, cb: (err: any, data?: R) => void) => {
if (this._callbacks.has(callbackId)) {
cb(new Error(`Nui Server Callback with name "${event}" is already waiting for server!`));
return;
}
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)) {
const callback = this._callbacks.get(callbackId);
clearTimeout(callback.timeout);
callback.cb(null, response);
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)) {
const callback = this._callbacks.get(callbackId);
clearTimeout(callback.timeout);
callback.cb(err);
this._callbacks.delete(callbackId);
sendMessage(app, _error, err);
}
});
}
+1
View File
@@ -10,6 +10,7 @@ import './cl_photo';
import './cl_messages';
import './cl_call';
import './cl_match';
import './cl_email';
import './functions';
export const ClUtils = new ClientUtils();
+1
View File
@@ -11,6 +11,7 @@ import './sv_photo';
import './sv_messages';
import './sv_match';
import './sv_call';
import './sv_email';
import './players/sv_player_events';
import { mainLogger } from './sv_logger';
+3 -2
View File
@@ -120,12 +120,13 @@ onNet(events.EMAIL_FETCH_INBOX, async () => {
try {
const email = '[email protected]';
const messages = await fetchInbox(email);
await new Promise((res) => setTimeout(res, 6000));
const inbox = getEmailsFromMessages(messages, email);
emitNet(events.EMAIL_FETCH_INBOX_SUCCESS, inbox);
emitNet(events.EMAIL_FETCH_INBOX_SUCCESS, _source, inbox);
} catch (e) {
emailLogger.error(`Failed to fetch email inbox, ${e.message}`, {
source: _source,
});
emitNet(events.EMAIL_FETCH_INBOX_ERROR, e);
emitNet(events.EMAIL_FETCH_INBOX_ERROR, _source, e);
}
});
+1
View File
@@ -1,4 +1,5 @@
export default {
EMAIL: 'EMAIL',
TWITTER: 'TWITTER',
MATCH: 'MATCH',
MESSAGES: 'MESSAGES',
+4
View File
@@ -37,3 +37,7 @@ export function sendCameraEvent(method: string, data: any = {}) {
export function sendMatchEvent(method: string, data: any = {}) {
return sendMessage(apps.MATCH, method, data);
}
export function sendEmailEvent(method: string, data: any = {}) {
sendMessage(apps.EMAIL, method, data);
}