diff --git a/config.json b/config.json
index 18697d0..61cb6c8 100644
--- a/config.json
+++ b/config.json
@@ -31,6 +31,9 @@
"generateProfileNameFromUsers": true,
"allowEdtiableProfileName": true
},
+ "email": {
+ "provider": "project-error.dev"
+ },
"bank": {
"showNotifications": true
},
diff --git a/import.sql b/import.sql
index 71936fd..576f01d 100644
--- a/import.sql
+++ b/import.sql
@@ -1,7 +1,7 @@
# comment this out if your server has a different table/location for phone_number
# or if it already exists in the users table
ALTER TABLE `users` ADD COLUMN `phone_number` VARCHAR(20) DEFAULT NULL;
-ALTER TABLE `users` ADD COLUMN `email` VARCHAR(255) DEFAULT NULL;
+ALTER TABLE `users` ADD COLUMN `phone_email` VARCHAR(255) DEFAULT NULL;
INSERT INTO `items` (`name`, `label`, `weight`, `rare`, `can_remove`) VALUES ('phone', 'Phone', 1, 0, 1);
INSERT INTO `items` (`name`, `label`, `weight`, `rare`, `can_remove`) VALUES ('dphone', 'Destroyed Phone', 1, 0, 1);
diff --git a/phone/public/media/icons/default/BANK.svg b/phone/public/media/icons/default/BANK.svg
new file mode 100644
index 0000000..af29579
--- /dev/null
+++ b/phone/public/media/icons/default/BANK.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/phone/public/media/icons/default/CALCULATOR.svg b/phone/public/media/icons/default/CALCULATOR.svg
new file mode 100644
index 0000000..d014a88
--- /dev/null
+++ b/phone/public/media/icons/default/CALCULATOR.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/phone/public/media/icons/default/CAMERA.svg b/phone/public/media/icons/default/CAMERA.svg
new file mode 100644
index 0000000..73cf471
--- /dev/null
+++ b/phone/public/media/icons/default/CAMERA.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/phone/public/media/icons/default/CONTACTS.svg b/phone/public/media/icons/default/CONTACTS.svg
new file mode 100644
index 0000000..7f71ddf
--- /dev/null
+++ b/phone/public/media/icons/default/CONTACTS.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/phone/public/media/icons/default/DIALER.svg b/phone/public/media/icons/default/DIALER.svg
new file mode 100644
index 0000000..8051dca
--- /dev/null
+++ b/phone/public/media/icons/default/DIALER.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/phone/public/media/icons/default/MESSAGES.svg b/phone/public/media/icons/default/MESSAGES.svg
new file mode 100644
index 0000000..0ad92e8
--- /dev/null
+++ b/phone/public/media/icons/default/MESSAGES.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/phone/public/media/icons/default/NOTES.svg b/phone/public/media/icons/default/NOTES.svg
new file mode 100644
index 0000000..d8b3c7b
--- /dev/null
+++ b/phone/public/media/icons/default/NOTES.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/phone/public/media/icons/default/SELLOUT.svg b/phone/public/media/icons/default/SELLOUT.svg
new file mode 100644
index 0000000..b791151
--- /dev/null
+++ b/phone/public/media/icons/default/SELLOUT.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/phone/public/media/icons/default/SETTINGS.svg b/phone/public/media/icons/default/SETTINGS.svg
new file mode 100644
index 0000000..517c6d9
--- /dev/null
+++ b/phone/public/media/icons/default/SETTINGS.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/phone/public/media/icons/default/TWITTER.svg b/phone/public/media/icons/default/TWITTER.svg
new file mode 100644
index 0000000..47e234b
--- /dev/null
+++ b/phone/public/media/icons/default/TWITTER.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/phone/public/media/logo/default.png b/phone/public/media/logo/default.png
new file mode 100644
index 0000000..6b52423
Binary files /dev/null and b/phone/public/media/logo/default.png differ
diff --git a/phone/src/os/apps/icons/BankAppIcon.tsx b/phone/src/os/apps/icons/BankAppIcon.tsx
new file mode 100644
index 0000000..94f767d
--- /dev/null
+++ b/phone/src/os/apps/icons/BankAppIcon.tsx
@@ -0,0 +1,26 @@
+import React from 'react';
+import SvgIcon, { SvgIconProps } from '@material-ui/core/SvgIcon';
+
+export const BankAppIcon = (props: SvgIconProps) => {
+ return (
+
+
+
+ );
+};
diff --git a/phone/src/os/apps/icons/CalculatorAppIcon.tsx b/phone/src/os/apps/icons/CalculatorAppIcon.tsx
new file mode 100644
index 0000000..c553a59
--- /dev/null
+++ b/phone/src/os/apps/icons/CalculatorAppIcon.tsx
@@ -0,0 +1,23 @@
+import React from 'react';
+import SvgIcon, { SvgIconProps } from '@material-ui/core/SvgIcon';
+
+export const CalculatorAppIcon = (props: SvgIconProps) => {
+ return (
+
+
+
+ );
+};
diff --git a/phone/src/os/apps/icons/CameraAppIcon.tsx b/phone/src/os/apps/icons/CameraAppIcon.tsx
new file mode 100644
index 0000000..3d29c58
--- /dev/null
+++ b/phone/src/os/apps/icons/CameraAppIcon.tsx
@@ -0,0 +1,25 @@
+import React from 'react';
+import SvgIcon, { SvgIconProps } from '@material-ui/core/SvgIcon';
+
+export const CameraAppIcon = (props: SvgIconProps) => {
+ return (
+
+
+
+ );
+};
diff --git a/phone/src/os/apps/icons/ContactsAppIcon.tsx b/phone/src/os/apps/icons/ContactsAppIcon.tsx
new file mode 100644
index 0000000..ba287e7
--- /dev/null
+++ b/phone/src/os/apps/icons/ContactsAppIcon.tsx
@@ -0,0 +1,23 @@
+import React from 'react';
+import SvgIcon, { SvgIconProps } from '@material-ui/core/SvgIcon';
+
+export const ContactsAppIcon = (props: SvgIconProps) => {
+ return (
+
+
+
+ );
+};
diff --git a/phone/src/os/apps/icons/DialerAppIcon.tsx b/phone/src/os/apps/icons/DialerAppIcon.tsx
new file mode 100644
index 0000000..64395f2
--- /dev/null
+++ b/phone/src/os/apps/icons/DialerAppIcon.tsx
@@ -0,0 +1,23 @@
+import React from 'react';
+import SvgIcon, { SvgIconProps } from '@material-ui/core/SvgIcon';
+
+export const DialerAppIcon = (props: SvgIconProps) => {
+ return (
+
+
+
+ );
+};
diff --git a/phone/src/os/apps/icons/MessagesAppIcon.tsx b/phone/src/os/apps/icons/MessagesAppIcon.tsx
new file mode 100644
index 0000000..f92f3f7
--- /dev/null
+++ b/phone/src/os/apps/icons/MessagesAppIcon.tsx
@@ -0,0 +1,30 @@
+import React from 'react';
+import SvgIcon, { SvgIconProps } from '@material-ui/core/SvgIcon';
+
+export const MessagesAppIcon = (props: SvgIconProps) => {
+ return (
+
+
+
+ );
+};
diff --git a/phone/src/os/apps/icons/NotesAppIcon.tsx b/phone/src/os/apps/icons/NotesAppIcon.tsx
new file mode 100644
index 0000000..9d4882c
--- /dev/null
+++ b/phone/src/os/apps/icons/NotesAppIcon.tsx
@@ -0,0 +1,23 @@
+import React from 'react';
+import SvgIcon, { SvgIconProps } from '@material-ui/core/SvgIcon';
+
+export const NotesAppIcon = (props: SvgIconProps) => {
+ return (
+
+
+
+ );
+};
diff --git a/phone/src/os/apps/icons/SelloutAppIcon.tsx b/phone/src/os/apps/icons/SelloutAppIcon.tsx
new file mode 100644
index 0000000..8502a7c
--- /dev/null
+++ b/phone/src/os/apps/icons/SelloutAppIcon.tsx
@@ -0,0 +1,26 @@
+import React from 'react';
+import SvgIcon, { SvgIconProps } from '@material-ui/core/SvgIcon';
+
+export const SelloutAppIcon = (props: SvgIconProps) => {
+ return (
+
+
+
+ );
+};
diff --git a/phone/src/os/apps/icons/SettingsAppIcon.tsx b/phone/src/os/apps/icons/SettingsAppIcon.tsx
new file mode 100644
index 0000000..3b590fd
--- /dev/null
+++ b/phone/src/os/apps/icons/SettingsAppIcon.tsx
@@ -0,0 +1,23 @@
+import React from 'react';
+import SvgIcon, { SvgIconProps } from '@material-ui/core/SvgIcon';
+
+export const SettingsAppIcon = (props: SvgIconProps) => {
+ return (
+
+
+
+ );
+};
diff --git a/phone/src/os/apps/icons/TwitterAppIcon.tsx b/phone/src/os/apps/icons/TwitterAppIcon.tsx
new file mode 100644
index 0000000..dbeb562
--- /dev/null
+++ b/phone/src/os/apps/icons/TwitterAppIcon.tsx
@@ -0,0 +1,23 @@
+import React from 'react';
+import SvgIcon, { SvgIconProps } from '@material-ui/core/SvgIcon';
+
+export const TwitterAppIcon = (props: SvgIconProps) => {
+ return (
+
+
+
+ );
+};
diff --git a/resources/client/cl_email.ts b/resources/client/cl_email.ts
index 409f45e..89bbe4a 100644
--- a/resources/client/cl_email.ts
+++ b/resources/client/cl_email.ts
@@ -1,66 +1,110 @@
-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(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([]);
-});
- */
+import { EmailEvents, EmailMessageInput, IEmailMessage } from '../../typings/email';
interface ICallback {
cb: (err: any, data?: unknown) => void;
timeout: NodeJS.Timeout;
}
-const event = events.EMAIL_FETCH_INBOX;
+const _timeout = 10000;
const _callbacks = new Map();
-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!`));
+/**
+ * Fetch Inbox
+ */
+RegisterNuiCallbackType(EmailEvents.FETCH_INBOX);
+on(`__cfx_nui:${EmailEvents.FETCH_INBOX}`, (data: any, cb: (err: any, data?: any) => void) => {
+ if (_callbacks.has(EmailEvents.FETCH_INBOX)) {
+ cb(
+ new Error(
+ `Nui Server Callback with name "${EmailEvents.FETCH_INBOX}" is already waiting for server!`,
+ ),
+ );
return;
}
- emitNet(event, data);
+ emitNet(EmailEvents.FETCH_INBOX, data);
- _callbacks.set(callbackId, {
+ _callbacks.set(EmailEvents.FETCH_INBOX, {
cb,
timeout: setTimeout(() => {
- if (_callbacks.has(callbackId)) {
+ if (_callbacks.has(EmailEvents.FETCH_INBOX)) {
_callbacks
- .get(callbackId)
- .cb(new Error(`Nui Server Callback with name "${event}" timed out`));
- _callbacks.delete(callbackId);
+ .get(EmailEvents.FETCH_INBOX)
+ .cb(new Error(`Nui Server Callback with name "${EmailEvents.FETCH_INBOX}" timed out`));
+ _callbacks.delete(EmailEvents.FETCH_INBOX);
}
- }, 20000),
+ }, _timeout),
});
});
-onNet(`${event}Success`, (response: any) => {
- if (_callbacks.has(callbackId)) {
- const callback = _callbacks.get(callbackId);
+onNet(EmailEvents.FETCH_INBOX_SUCCESS, (response: any) => {
+ if (_callbacks.has(EmailEvents.FETCH_INBOX)) {
+ const callback = _callbacks.get(EmailEvents.FETCH_INBOX);
clearTimeout(callback.timeout);
callback.cb(null, response);
- _callbacks.delete(callbackId);
- sendEmailEvent(`${event}Success`, response);
+ _callbacks.delete(EmailEvents.FETCH_INBOX);
+ sendEmailEvent(EmailEvents.FETCH_INBOX_SUCCESS, response);
}
});
-onNet(`${event}Error`, (err: any) => {
- if (_callbacks.has(callbackId)) {
- const callback = _callbacks.get(callbackId);
+onNet(EmailEvents.FETCH_INBOX_ERROR, (err: any) => {
+ if (_callbacks.has(EmailEvents.FETCH_INBOX)) {
+ const callback = _callbacks.get(EmailEvents.FETCH_INBOX);
clearTimeout(callback.timeout);
callback.cb(err);
- _callbacks.delete(callbackId);
- sendEmailEvent(`${event}Error`, err);
+ _callbacks.delete(EmailEvents.FETCH_INBOX);
+ sendEmailEvent(EmailEvents.FETCH_INBOX_ERROR, err);
+ }
+});
+
+/**
+ * Send Email
+ */
+RegisterNuiCallbackType(EmailEvents.SEND_EMAIL);
+on(
+ `__cfx_nui:${EmailEvents.SEND_EMAIL}`,
+ (data: EmailMessageInput, cb: (err: any, data?: IEmailMessage) => void) => {
+ if (_callbacks.has(EmailEvents.SEND_EMAIL)) {
+ cb(
+ new Error(
+ `Nui Server Callback with name "${EmailEvents.SEND_EMAIL}" is already waiting for server!`,
+ ),
+ );
+ return;
+ }
+ emitNet(EmailEvents.SEND_EMAIL, data);
+
+ _callbacks.set(EmailEvents.SEND_EMAIL, {
+ cb,
+ timeout: setTimeout(() => {
+ if (_callbacks.has(EmailEvents.SEND_EMAIL)) {
+ _callbacks
+ .get(EmailEvents.SEND_EMAIL)
+ .cb(new Error(`Nui Server Callback with name "${EmailEvents.SEND_EMAIL}" timed out`));
+ _callbacks.delete(EmailEvents.SEND_EMAIL);
+ }
+ }, _timeout),
+ });
+ },
+);
+
+onNet(EmailEvents.SEND_EMAIL_SUCCESS, (response: any) => {
+ if (_callbacks.has(EmailEvents.SEND_EMAIL)) {
+ const callback = _callbacks.get(EmailEvents.SEND_EMAIL);
+ clearTimeout(callback.timeout);
+ callback.cb(null, response);
+ _callbacks.delete(EmailEvents.SEND_EMAIL);
+ sendEmailEvent(EmailEvents.SEND_EMAIL_SUCCESS, response);
+ }
+});
+
+onNet(EmailEvents.SEND_EMAIL_ERROR, (err: any) => {
+ if (_callbacks.has(EmailEvents.SEND_EMAIL)) {
+ const callback = _callbacks.get(EmailEvents.SEND_EMAIL);
+ clearTimeout(callback.timeout);
+ callback.cb(err);
+ _callbacks.delete(EmailEvents.SEND_EMAIL);
+ sendEmailEvent(EmailEvents.SEND_EMAIL_ERROR, err);
}
});
diff --git a/resources/server/functions.ts b/resources/server/functions.ts
index ab91bc8..c477ce8 100644
--- a/resources/server/functions.ts
+++ b/resources/server/functions.ts
@@ -1,7 +1,7 @@
import { pool } from './db';
import config from '../utils/config';
import { mainLogger } from './sv_logger';
-import { Player, Players, PlayersByIdentifier } from './players/sv_players';
+import { getDefaultProfileNames, Player, Players, PlayersByIdentifier } from './players/sv_players';
export function getPlayer(source: number): Player {
const player = Players.get(source);
@@ -43,6 +43,25 @@ export async function getIdentifierByPhoneNumber(
return null;
}
+/**
+ * Return the attached identifier for a given email
+ * @param email The email to return identifier for
+ * @param fetch Whether or not to query the database if a given player is offline
+ **/
+export async function getIdentifierByEmail(email: string, fetch?: boolean): Promise {
+ for (const [source, player] of Players) {
+ if (player.getEmail() === email) return player.identifier;
+ }
+ // Whether we fetch from database if not found in online players
+ if (fetch) {
+ const query = `SELECT identifier FROM users WHERE phone_email = ?`;
+ const [results] = await pool.query(query, [email]);
+ // Get identifier from results
+ return (results as { identifier: string }[])[0].identifier;
+ }
+ return null;
+}
+
/**
* Returns the player phoneNumber for a passed identifier
* @param identifier The players phone number
@@ -70,7 +89,7 @@ function getRandomPhoneNumber() {
return randomNumber;
}
-export async function generatePhoneNumber(identifier: string): Promise {
+export async function generatePhoneNumber(identifier: string): Promise {
const getQuery = `SELECT phone_number FROM users WHERE identifier = ?`;
const [results] = await pool.query(getQuery, [identifier]);
const result = results;
@@ -87,8 +106,34 @@ export async function generatePhoneNumber(identifier: string): Promise {
existingId = false;
}
} while (existingId);
- mainLogger.debug(`Inserting number into Database: ${newNumber}`);
const query = 'UPDATE users SET phone_number = ? WHERE identifier = ?';
await pool.query(query, [newNumber, identifier]);
+ mainLogger.debug(`Inserting number into Database: ${newNumber}`);
+ return newNumber;
}
+ return phoneNumber;
+}
+
+export async function generateEmail(identifier: string): Promise {
+ const getQuery = `SELECT phone_email FROM users WHERE identifier = ?`;
+ const [results] = await pool.query(getQuery, [identifier]);
+ const result = results;
+ const email = result[0]?.phone_email;
+
+ if (!email) {
+ const emailUser = await getDefaultProfileNames(identifier);
+
+ if (!emailUser) {
+ throw new Error('Must provide a fullName or phoneNumber option to create an email');
+ }
+
+ const emailProvider = config.email.provider || 'project-error.dev';
+
+ const newEmail = `${emailUser}@${emailProvider}`;
+ const query = 'UPDATE users SET phone_email = ? WHERE identifier = ?';
+ await pool.query(query, [newEmail, identifier]);
+ mainLogger.debug(`Inserting email into Database: ${newEmail}`);
+ return newEmail;
+ }
+ return email;
}
diff --git a/resources/server/players/sv_players.ts b/resources/server/players/sv_players.ts
index 93a79db..ebba2fe 100644
--- a/resources/server/players/sv_players.ts
+++ b/resources/server/players/sv_players.ts
@@ -1,6 +1,6 @@
import { mainLogger } from '../sv_logger';
import { pool } from '../db';
-import { generatePhoneNumber } from '../functions';
+import { generateEmail, generatePhoneNumber } from '../functions';
import { PhoneEvents } from '../../../typings/phone';
export const playerLogger = mainLogger.child({
@@ -37,12 +37,15 @@ export async function handlePlayerAdd(pSource: number) {
// Get player info to populate class instance
const { firstname, lastname, phone_number } = await getPlayerInfo(playerIdentifer);
+ const email = await generateEmail(playerIdentifer);
+
const newPlayer = new Player({
identifier: playerIdentifer,
source: pSource,
username,
firstname,
lastname,
+ email,
phoneNumber: phone_number,
});
@@ -150,6 +153,7 @@ interface PlayerClassArgs {
lastname: string;
identifier: string;
phoneNumber: string;
+ email: string;
}
// Public getters/setters are for servers with multicharacter systems
@@ -162,13 +166,23 @@ export class Player {
private _firstname: string;
private _lastname: string;
private _phoneNumber: string;
+ private _email: string;
- constructor({ source, firstname, lastname, identifier, phoneNumber, username }: PlayerClassArgs) {
+ constructor({
+ source,
+ firstname,
+ lastname,
+ identifier,
+ phoneNumber,
+ username,
+ email,
+ }: PlayerClassArgs) {
this.source = source;
this.identifier = identifier;
this._firstname = firstname;
this._lastname = lastname;
this._phoneNumber = phoneNumber;
+ this._email = email;
this.username = username;
}
/**
@@ -221,4 +235,18 @@ export class Player {
public setPhoneNumber(number: string): void {
this._phoneNumber = number;
}
+
+ /**
+ * Set the stored phone email for a user
+ **/
+ public setEmail(email: string): void {
+ this._email = email;
+ }
+
+ /**
+ * Get the stored phone email for a user
+ **/
+ public getEmail(): string {
+ return this._email;
+ }
}
diff --git a/resources/server/sv_email.ts b/resources/server/sv_email.ts
index 7c34849..6cbea95 100644
--- a/resources/server/sv_email.ts
+++ b/resources/server/sv_email.ts
@@ -1,8 +1,10 @@
-import events from '../utils/events';
+import { EmailEvents, EmailMessageInput } from '../../typings/email';
import { mainLogger } from './sv_logger';
-import { getSource } from './functions';
+import { getIdentifierByEmail, getPlayer, getSource } from './functions';
import { IEmail, IEmailMessage } from '../../phone/src/common/typings/email';
import { pool } from './db';
+import config from '../utils/config';
+import { getPlayerInfo } from './players/sv_players';
const emailLogger = mainLogger.child({ module: 'contact' });
@@ -115,18 +117,96 @@ function getEmailsFromMessages(messages: UnformattedEmailMessage[], myEmail: str
return Array.from(map.values()).map((m) => ({ ...m, messagesMap: undefined }));
}
-onNet(events.EMAIL_FETCH_INBOX, async () => {
+async function sendEmail(
+ sender_identifier: string,
+ sender: string,
+ receivers: { email: string; identifier: string }[],
+ body: string,
+ email_id_or_subject: number | string,
+ parent_id?: number,
+) {
+ let email_id = email_id_or_subject === 'number' ? email_id_or_subject : undefined;
+ if (typeof email_id_or_subject === 'string') {
+ const emailQuery = `INSERT INTO npwd_emails (subject) VALUES (?)`;
+ const [emailResult] = await pool.query(emailQuery, [email_id_or_subject]);
+ email_id = (emailResult as any).insertId;
+ }
+ const messageQuery = `INSERT INTO npwd_emails_messages (email_id, parent_id, send_date, body, sender, sender_identifier) VALUES (?, ?, ?, ?, ?, ?)`;
+ const [messageResult] = await pool.query(messageQuery, [
+ email_id,
+ parent_id || null,
+ Math.floor(Date.now() / 1000),
+ body,
+ sender,
+ sender_identifier,
+ ]);
+
+ const message_id = (messageResult as any).insertId;
+
+ const receiverQuery = `INSERT INTO npwd_emails_receivers (message_id, receiver, receiver_identifier, read_at) VALUES (?, ?, ?, ?)`;
+ const receiverPromises = receivers.map((r) =>
+ pool.query(receiverQuery, [message_id, r.email, r.identifier, null]),
+ );
+
+ await Promise.all(receiverPromises);
+
+ return messageResult;
+}
+
+onNet(EmailEvents.FETCH_INBOX, async () => {
const _source = getSource();
try {
- const email = 'kidz@projecterror.dev';
- const messages = await fetchInbox(email);
- await new Promise((res) => setTimeout(res, 6000));
- const inbox = getEmailsFromMessages(messages, email);
- emitNet(events.EMAIL_FETCH_INBOX_SUCCESS, _source, inbox);
+ const player = getPlayer(_source);
+ if (!player) {
+ throw new Error('Couldnt find player');
+ }
+ const playerEmail = player.getEmail();
+ const messages = await fetchInbox(player.identifier);
+ const inbox = getEmailsFromMessages(messages, playerEmail);
+ emitNet(EmailEvents.FETCH_INBOX_SUCCESS, _source, inbox);
} catch (e) {
emailLogger.error(`Failed to fetch email inbox, ${e.message}`, {
source: _source,
});
- emitNet(events.EMAIL_FETCH_INBOX_ERROR, _source, e);
+ emitNet(EmailEvents.FETCH_INBOX_ERROR, _source, e);
}
});
+
+onNet(
+ EmailEvents.SEND_EMAIL,
+ async ({ email_id, subject, parent_id, body, receivers }: EmailMessageInput) => {
+ const _source = getSource();
+ try {
+ const player = getPlayer(_source);
+ if (!player) {
+ throw new Error('Couldnt find player');
+ }
+
+ const mappedReceivers = await Promise.all(
+ receivers
+ .split(',')
+ .map((s: string) => s.trim())
+ .map(async (email: string) => {
+ const identifier = await getIdentifierByEmail(email);
+ return { email, identifier };
+ }),
+ );
+
+ const email = await sendEmail(
+ player.identifier,
+ player.getEmail(),
+ mappedReceivers,
+ body,
+ email_id || subject,
+ parent_id || null,
+ );
+
+ emitNet(EmailEvents.SEND_EMAIL_SUCCESS, _source, email);
+ } catch (e) {
+ emailLogger.error(`Failed to send email, ${e.message}`, {
+ source: _source,
+ });
+ emitNet(EmailEvents.SEND_EMAIL_ERROR, _source, e);
+ }
+ },
+);
diff --git a/resources/utils/events.ts b/resources/utils/events.ts
deleted file mode 100644
index fac43d3..0000000
--- a/resources/utils/events.ts
+++ /dev/null
@@ -1,135 +0,0 @@
-export default {
- // Twitter
- TWITTER_FETCH_TWEETS: 'phone:fetchTweets',
- TWITTER_FETCH_TWEETS_SUCCESS: 'fetchTweets',
- TWITTER_FETCH_TWEETS_FAILURE: 'fetchTweetsFailed',
- TWITTER_FETCH_TWEETS_FILTERED: 'phone:fetchTweetsFiltered',
- TWITTER_FETCH_TWEETS_FILTERED_SUCCESS: 'fetchTweetsFiltered',
- TWITTER_FETCH_TWEETS_FILTERED_FAILURE: 'fetchTweetsFilteredFailed',
- TWITTER_GET_OR_CREATE_PROFILE: 'phone:getOrCreateTwitterProfile',
- TWITTER_GET_OR_CREATE_PROFILE_SUCCESS: 'getOrCreateTwitterProfile',
- TWITTER_GET_OR_CREATE_PROFILE_FAILURE: 'getOrCreateTwitterProfileFailed',
- TWITTER_UPDATE_PROFILE: 'phone:updateTwitterProfile',
- TWITTER_UPDATE_PROFILE_LOADING: 'updateProfileLoading',
- TWITTER_UPDATE_PROFILE_RESULT: 'updateProfileResult',
- TWITTER_CREATE_TWEET: 'phone:createTweet',
- TWITTER_CREATE_TWEET_LOADING: 'createTweetLoading',
- TWITTER_CREATE_TWEET_RESULT: 'createTweetResult',
- TWITTER_CREATE_TWEET_BROADCAST: 'createTweetBroadcast',
- TWITTER_CREATE_TWEET_FAILURE: 'createTweetResultFailed',
- TWITTER_DELETE_TWEET: 'phone:deleteTweet',
- TWITTER_DELETE_TWEET_SUCCESS: 'deleteTweetSuccess',
- TWITTER_DELETE_TWEET_FAILURE: 'deleteTweetFailed',
- TWITTER_TOGGLE_LIKE: 'phone:toggleLike',
- TWITTER_TOGGLE_LIKE_SUCCESS: 'toggleLikeSuccess',
- TWITTER_TOGGLE_LIKE_FAILURE: 'toggleLikeFailed',
- TWITTER_RETWEET: 'phone:retweet',
- TWITTER_RETWEET_SUCCESS: 'phone:retweetSuccess',
- TWITTER_RETWEET_EXISTS: 'phone:retweetExists',
- TWITTER_RETWEET_FAILURE: 'phone:retweetFailed',
- TWITTER_REPORT: 'phone:reportTweet',
- TWITTER_REPORT_SUCCESS: 'reportTweetSuccess',
- TWITTER_REPORT_FAILURE: 'reportTweetFailed',
-
- // Contacts
- CONTACTS_SEND_CONTACTS: 'phone:sendContacts',
- CONTACTS_GET_CONTACTS: 'phone:getContacts',
- CONTACTS_ADD_CONTACT_NUI: 'contacts:add',
- CONTACTS_ADD_CONTACT: 'phone:addContacts',
- CONTACTS_ADD_CONTACT_SUCCESS: 'contacts:addSuccess',
- CONTACTS_UPDATE_CONTACT: 'phone:updateContact',
- CONTACTS_DELETE_CONTACT: 'phone:deleteContact',
- CONTACTS_DELETE_CONTACT_SUCCESS: 'contacts:deleteSuccess',
- CONTACTS_UPDATE_CONTACT_SUCCESS: 'phone:updateContactSuccess',
- CONTACTS_ACTION_RESULT: 'phone:contactActionResult',
-
- // Sellout
- // these event keys needs to be changed to 'MARKETPLACE'
- SELLOUT_ADD_LISTING: 'phone:addListing',
- SELLOUT_ADD_LISTING_SUCCESS: 'phone:addListingSuccess',
- SELLOUT_FETCH_LISTING: 'phone:fetchAllListings',
- SELLOUT_SEND_LISTING: 'phone:sendAllListings',
- SELLOUT_ACTION_RESULT: 'phone:selloutActionResult',
- SELLOUT_DELETE_LISTING: 'phone:marketplaceDeleteListing',
- SELLOUT_DELETE_LISTING_SUCCESS: 'phone:marketplaceDeleteListingSuccess',
- SELLOUT_REPORT_LISTING: 'phone:reportListing',
- SELLOUT_REPORT_LISTING_SUCCESS: 'phone:reportListingSuccess',
- SELLOUT_REPORT_LISTING_SUCESS: 'phone:reportListingFailed',
-
- //
- BANK_ADD_TRANSFER: 'phone:addTransfer',
- BANK_ADD_TRANSFER_SUCCESS: 'phone:addTransferSuccess',
- BANK_FETCH_TRANSACTIONS: 'phone:fetchAllTransactions',
- BANK_SEND_TRANSFERS: 'phone:sendTransfers',
- BANK_TRANSACTION_ALERT: 'phone:bankTransactionAlert',
- BANK_TRANSACTION_NOTIFICATION: 'phone:bankTransactionNotification',
- BANK_SEND_CREDENTIALS: 'phone:sendBankCredentials',
- BANK_GET_CREDENTIALS: 'phone:getBankCredentials',
-
- //messages
- MESSAGES_FETCH_MESSAGE_GROUPS: 'phone:fetchMessageGroups',
- MESSAGES_FETCH_MESSAGE_GROUPS_SUCCESS: 'phone:fetchMessageGroupsSuccess',
- MESSAGES_FETCH_MESSAGE_GROUPS_FAILED: 'phone:fetchMessageGroupsFailed',
- MESSAGES_CREATE_MESSAGE_GROUP: 'phone:createMessageGroup',
- MESSAGES_CREATE_MESSAGE_GROUP_SUCCESS: 'phone:createMessageGroupSuccess',
- MESSAGES_CREATE_MESSAGE_GROUP_FAILED: 'phone:createMessageGroupFailed',
- MESSAGES_SEND_MESSAGE: 'phone:sendMessage',
- MESSAGES_SEND_MESSAGE_SUCCESS: 'phone:sendMessageSuccess',
- MESSAGES_SEND_MESSAGE_FAILED: 'phone:sendMessageFailed',
- MESSAGES_FETCH_MESSAGES: 'phone:fetchMessages',
- MESSAGES_FETCH_MESSAGES_SUCCESS: 'phone:fetchMessagesSuccess',
- MESSAGES_FETCH_MESSAGES_FAILED: 'phone:fetchMessagesFailed',
- MESSAGES_ACTION_RESULT: 'phone:setMessagesAlert',
- MESSAGES_CREATE_MESSAGE_BROADCAST: 'createMessagesBroadcast',
- MESSAGES_SET_MESSAGE_READ: 'phone:setReadMessages',
-
- // Notes
- NOTE_ADD_NOTE: 'phone:addNote',
- NOTE_FETCH_ALL_NOTES: 'phone:fetchAllNotes',
- NOTE_SEND_NOTE: 'phone:sendNote',
- NOTE_SEND_NOTE_SUCCESS: 'phone:sendNoteSuccess',
- NOTE_DELETE_NOTE: 'phone:deleteNote',
- NOTE_DELETE_NOTE_SUCCESS: 'phone:deleteNoteSuccess',
- NOTE_UPDATE_NOTE: 'phone:updateNote',
- NOTE_UPDATE_NOTE_SUCCESS: 'phone:updateNoteSuccess',
- NOTE_UPDATE_NOTE_FAILURE: 'phone:updateNoteFailure',
- NOTE_ACTION_RESULT: 'phone:notesActionResult',
-
- // DO NOT CHANGE WHATS BELOW, PLEASE - CHIP
- PLAYER_IS_READY: 'phone:playerIsReady',
- OPEN_APP_CONTACTS: 'phone:app:CONTACTS',
- OPEN_APP_BANK: 'phone:app:BANK',
- OPEN_APP_NOTES: 'phone:app:NOTES',
- OPEN_APP_LISTINGS: 'phone:app:SELLOUT',
- OPEN_APP_CAMERA: 'phone:app:CAMERA',
- OPEN_APP_DAILER: 'phone:app:DIALER',
-
- // camera
- CAMERA_TAKE_PHOTO: 'phone:TakePhoto',
- CAMERA_UPLOAD_PHOTO: 'phone:UploadPhoto',
- CAMERA_UPLOAD_PHOTO_SUCCESS: 'phone:UploadPhotoSuccess',
- CAMERA_FETCH_PHOTOS: 'phone:FetchPhotos',
- CAMERA_SEND_PHOTOS: 'phone:SendPhotos',
- CAMERA_DELETE_PHOTO: 'photo:deletePhoto',
- CAMERA_DELETE_PHOTO_SUCCESS: 'phone:deletePhotoSuccess',
- // copy
- PHONE_USE_CLIPBOARD: 'phone:useClipboard',
-
- // calling
- PHONE_INITIALIZE_CALL: 'phone:beginCall',
- PHONE_START_CALL: 'phone:startCall',
- PHONE_ACCEPT_CALL: 'phone:acceptCall',
- PHONE_END_CALL: 'phone:endCall',
- PHONE_CALL_WAS_ENDED: 'phone:callEnded',
- PHONE_CALL_WAS_ACCEPTED: 'phone:callAccepted',
- PHONE_CALL_REJECTED: 'phone:rejectCall',
- PHONE_CALL_WAS_REJECTED: 'phone:callRejected',
- PHONE_CALL_FETCH_CALLS: 'phone:fetchCalls',
- PHONE_CALL_SEND_HISTORY: 'phone:sendCallHistory',
- PHONE_CALL_SEND_HANGUP_ANIM: 'phone:sendHangupAnim',
-
- // email
- EMAIL_FETCH_INBOX: 'phone:fetchInbox',
- EMAIL_FETCH_INBOX_SUCCESS: 'phone:fetchInboxSuccess',
- EMAIL_FETCH_INBOX_ERROR: 'phone:fetchInboxError',
-};
diff --git a/typings/config.ts b/typings/config.ts
index 4090c76..ddf428b 100644
--- a/typings/config.ts
+++ b/typings/config.ts
@@ -16,6 +16,11 @@ interface MatchConfig {
generateProfileNameFromUsers: boolean;
allowEdtiableProfileName: boolean;
}
+
+interface EmailConfig {
+ provider: string;
+}
+
interface Debug {
level: 'error' | 'warn' | 'info' | 'verbose' | 'debug';
enabled: boolean;
@@ -46,6 +51,7 @@ export interface IServerConfig {
twitter: TwitterConfig;
match: MatchConfig;
bank: BankConfig;
+ email: EmailConfig;
notificationPosition: NotificationConfig;
general: General;
debug: Debug;
diff --git a/phone/src/common/typings/email.ts b/typings/email.ts
similarity index 56%
rename from phone/src/common/typings/email.ts
rename to typings/email.ts
index 236ee84..0b8fd75 100644
--- a/phone/src/common/typings/email.ts
+++ b/typings/email.ts
@@ -27,3 +27,20 @@ export interface IEmail {
subject: string;
messages: IEmailMessage[];
}
+
+export interface EmailMessageInput {
+ email_id?: number;
+ subject?: string;
+ parent_id?: number;
+ body: string;
+ receivers: string;
+}
+
+export enum EmailEvents {
+ FETCH_INBOX = 'npwd:fetchEmailInbox',
+ FETCH_INBOX_SUCCESS = 'npwd:fetchEmailInboxSuccess',
+ FETCH_INBOX_ERROR = 'npwd:fetchEmailInboxError',
+ SEND_EMAIL = 'npwd:sendEmail',
+ SEND_EMAIL_SUCCESS = 'npwd:sendEmailSuccess',
+ SEND_EMAIL_ERROR = 'npwd:sendEmailError',
+}