refactor(events): Events are now tied to a common enum typings (#167)

* chore(scripts/twitter): Refactored twitter to use event enums

* chore(scripts/marketplace): Refactored marketplace to use event enums

* chore(scripts/messages): Refactored messages to use event enums

* chore(scripts/contacts): Refactored contacts to use event enums

* chore(scripts/calls): Refactored calls to use event enums

* chore(scripts/notes): Refactored notes to use event enums

* chore(scripts/photos): Refactored photos to use event enums

* chore(scripts/bank): Refactored bank to use event enums

* chore(scripts/phone): Refactored phone to use event enums

* chore(events): Removed old events object

* refactor(phone/nui-events): Attached NUI events to respective enum

* tweak(event-enums): Added npwd prefix to all events

* tweak(phone/serve): Added craco to override CRA without eject

Also bumped react-scripts to 4.0.1, with seemingly no issues

* fix(typings/twitter): Fixed method enums for twitter
This commit is contained in:
Taso authored and GitHub committed 2021-03-22 13:37:07 -04:00
1 parent 53d5bb459d
commit 0f61088999
62 files changed
+4734 -3470

No files matched your search

+15 -15
View File
@@ -1,7 +1,7 @@
import { pool } from './db';
import events from '../utils/events';
import { getIdentifier, getSource } from './functions';
import { mainLogger } from './sv_logger';
import { ContactEvents } from '../../typings/contact';
const contactsLogger = mainLogger.child({ module: 'contact' });
@@ -52,30 +52,30 @@ async function deleteContact(contact: ContactId, identifier: string): Promise<an
await pool.query(query, [contact.id, identifier]);
}
onNet(events.CONTACTS_GET_CONTACTS, async () => {
onNet(ContactEvents.GET_CONTACTS, async () => {
const _source = getSource();
try {
const _identifier = getIdentifier(_source);
const contacts = await fetchAllContacts(_identifier);
emitNet(events.CONTACTS_SEND_CONTACTS, _source, contacts);
emitNet(ContactEvents.SEND_CONTACTS, _source, contacts);
} catch (e) {
contactsLogger.error(`Failed to fetch contacts, ${e.message}`);
}
});
onNet(events.CONTACTS_ADD_CONTACT, async (number: string, display: string, avatar: string) => {
onNet(ContactEvents.ADD_CONTACT, async (number: string, display: string, avatar: string) => {
const _source = getSource();
try {
const _identifier = getIdentifier(_source);
await addContact(_identifier, number, display, avatar);
emitNet(events.CONTACTS_ADD_CONTACT_SUCCESS, _source);
emitNet(events.CONTACTS_ACTION_RESULT, _source, {
emitNet(ContactEvents.ADD_CONTACT_SUCCESS, _source);
emitNet(ContactEvents.ACTION_RESULT, _source, {
message: 'CONTACT_ADD_SUCCESS',
type: 'success',
});
} catch (e) {
emitNet(events.CONTACTS_ACTION_RESULT, _source, {
emitNet(ContactEvents.ACTION_RESULT, _source, {
message: 'CONTACT_ADD_FAILED',
type: 'error',
});
@@ -85,21 +85,21 @@ onNet(events.CONTACTS_ADD_CONTACT, async (number: string, display: string, avata
}
});
onNet(events.CONTACTS_UPDATE_CONTACT, async (contact: Contacts) => {
onNet(ContactEvents.UPDATE_CONTACT, async (contact: Contacts) => {
const _source = getSource();
try {
const _identifier = getIdentifier(_source);
await updateContact(contact, _identifier);
emitNet(events.CONTACTS_UPDATE_CONTACT_SUCCESS, _source);
emitNet(ContactEvents.UPDATE_CONTACT_SUCCESS, _source);
emitNet(events.CONTACTS_ACTION_RESULT, _source, {
emitNet(ContactEvents.ACTION_RESULT, _source, {
message: 'CONTACT_UPDATE_SUCCESS',
type: 'success',
});
} catch (e) {
const _source = (global as any).source;
emitNet(events.CONTACTS_ACTION_RESULT, _source, {
emitNet(ContactEvents.ACTION_RESULT, _source, {
message: 'CONTACT_UPDATE_FAILED',
type: 'error',
});
@@ -109,13 +109,13 @@ onNet(events.CONTACTS_UPDATE_CONTACT, async (contact: Contacts) => {
}
});
onNet(events.CONTACTS_DELETE_CONTACT, async (contact: ContactId) => {
onNet(ContactEvents.DELETE_CONTACT, async (contact: ContactId) => {
const _source = getSource();
try {
const _identifier = getIdentifier(_source);
await deleteContact(contact, _identifier);
emitNet(events.CONTACTS_DELETE_CONTACT_SUCCESS, _source);
emitNet(events.CONTACTS_ACTION_RESULT, _source, {
emitNet(ContactEvents.DELETE_CONTACT_SUCCESS, _source);
emitNet(ContactEvents.ACTION_RESULT, _source, {
message: 'CONTACT_DELETE_SUCCESS',
type: 'success',
});
@@ -123,7 +123,7 @@ onNet(events.CONTACTS_DELETE_CONTACT, async (contact: ContactId) => {
contactsLogger.error(`Failed to delete contact, ${e.message}`, {
source: _source,
});
emitNet(events.CONTACTS_ACTION_RESULT, _source, {
emitNet(ContactEvents.ACTION_RESULT, _source, {
message: 'CONTACT_DELETE_FAILED',
type: 'error',
});