mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 06:28:51 +00:00
Phone actions can be triggered from outside the phone via email
This commit is contained in:
1 parent
901d7e95d3
commit
0a5a49b3d5
8 files changed
+67
-32
No files matched your search
+2
-1
@@ -32,7 +32,8 @@
|
||||
"allowEdtiableProfileName": true
|
||||
},
|
||||
"email": {
|
||||
"provider": "project-error.dev"
|
||||
"provider": "project-error.dev",
|
||||
"welcomeEmail": "You have got a new phone number registered to you"
|
||||
},
|
||||
"bank": {
|
||||
"showNotifications": true
|
||||
|
||||
@@ -3,10 +3,22 @@ import ReplyAllIcon from '@material-ui/icons/ReplyAll';
|
||||
import ReplyIcon from '@material-ui/icons/Reply';
|
||||
import { Box, Button, Card, CardActions, CardContent, Typography } from '@material-ui/core';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { IEmailMessage, EmailEvents } from '../../../../../../typings/email';
|
||||
import { IEmailMessage, EmailEvents, IEmail } from '../../../../../../typings/email';
|
||||
import { useEmail } from '../../hooks/useEmail';
|
||||
import { useNuiEventCallback } from '../../../../os/nui-events/hooks/useNuiEventCallback';
|
||||
import { useHistory } from 'react-router';
|
||||
import { TFunction } from 'i18next';
|
||||
|
||||
const mapParagraphs = (paragraph: string, t: TFunction) => {
|
||||
const isTranslate = paragraph.includes('--translate-');
|
||||
const [, tKey] = paragraph.split('--translate-');
|
||||
const text = isTranslate ? t(tKey) : paragraph;
|
||||
return (
|
||||
<Typography variant="caption" paragraph>
|
||||
{text}
|
||||
</Typography>
|
||||
);
|
||||
};
|
||||
|
||||
export const EmailMessage = ({ message, subject }: { message: IEmailMessage; subject: string }) => {
|
||||
const history = useHistory();
|
||||
@@ -17,17 +29,16 @@ export const EmailMessage = ({ message, subject }: { message: IEmailMessage; sub
|
||||
Pick<IEmailMessage, 'phoneActions' | 'externalActions'>
|
||||
>({});
|
||||
|
||||
const [fetchEmailActions, { loading }] = useNuiEventCallback(
|
||||
'EMAIL',
|
||||
EmailEvents.FETCH_MESSAGE_ACTIONS,
|
||||
setActions,
|
||||
);
|
||||
const [fetchEmailActions, { loading }] = useNuiEventCallback<
|
||||
{ messageId: number },
|
||||
Pick<IEmailMessage, 'phoneActions' | 'externalActions'>
|
||||
>('EMAIL', EmailEvents.FETCH_MESSAGE_ACTIONS, setActions);
|
||||
|
||||
useEffect(() => {
|
||||
if (message.hasActions) {
|
||||
fetchEmailActions();
|
||||
fetchEmailActions({ messageId: message.id });
|
||||
}
|
||||
}, [fetchEmailActions, message.hasActions]);
|
||||
}, [fetchEmailActions, message.hasActions, message.id]);
|
||||
|
||||
return (
|
||||
<Box px={2}>
|
||||
@@ -45,13 +56,7 @@ export const EmailMessage = ({ message, subject }: { message: IEmailMessage; sub
|
||||
</Card>
|
||||
<Box mt={2}>
|
||||
<Card>
|
||||
<CardContent>
|
||||
{message.body.split('\n').map((paragraph) => (
|
||||
<Typography variant="caption" paragraph>
|
||||
{paragraph}
|
||||
</Typography>
|
||||
))}
|
||||
</CardContent>
|
||||
<CardContent>{message.body.split('\n').map((p) => mapParagraphs(p, t))}</CardContent>
|
||||
</Card>
|
||||
{message.hasActions && phoneActions && (
|
||||
<CardActions>
|
||||
|
||||
@@ -32,7 +32,8 @@
|
||||
"allowEdtiableProfileName": true
|
||||
},
|
||||
"email": {
|
||||
"provider": "project-error.dev"
|
||||
"provider": "project-error.dev",
|
||||
"welcomeEmail": "You have got a new phone number registered to you"
|
||||
},
|
||||
"bank": {
|
||||
"showNotifications": true
|
||||
|
||||
@@ -203,6 +203,7 @@
|
||||
"APPS_MARKETPLACE_FORM_IMAGE": "Image or URL",
|
||||
"APPS_MARKETPLACE_FORM_DESCRIPTION": "Description",
|
||||
|
||||
"APPS_EMAIL_WELCOME": "Thanks for using New Phone Who Dis, your email is listed above and your registered phone number is: ",
|
||||
"APPS_EMAIL_INBOX": "Inbox",
|
||||
"APPS_EMAIL_SENT": "Sent",
|
||||
"APPS_EMAIL_SUBJECT": "Subject",
|
||||
|
||||
@@ -43,27 +43,32 @@ export async function fetchMessageActions(
|
||||
}> {
|
||||
const queryPhoneActions = `
|
||||
SELECT
|
||||
npwd_emails_phone_actions.label as action_phone_label,
|
||||
npwd_emails_phone_actions.close_phone as action_phone_close_phone,
|
||||
npwd_emails_phone_actions.delete_email as action_phone_delete_email,
|
||||
npwd_emails_phone_actions.href as action_phone_href
|
||||
npwd_emails_phone_actions.label,
|
||||
npwd_emails_phone_actions.close_phone,
|
||||
npwd_emails_phone_actions.delete_email,
|
||||
npwd_emails_phone_actions.href
|
||||
FROM npwd_emails_phone_actions
|
||||
WHERE message_id = ?;
|
||||
WHERE message_id = ?
|
||||
`;
|
||||
const queryExternalActions = `
|
||||
SELECT
|
||||
npwd_emails_external_actions.label as action_ext_label,
|
||||
npwd_emails_external_actions.close_phone as action_ext_close_phone,
|
||||
npwd_emails_external_actions.delete_email as action_ext_delete_email,
|
||||
npwd_emails_external_actions.event_name as action_ext_event_name,
|
||||
npwd_emails_external_actions.event_arg as action_ext_event_arg,
|
||||
npwd_emails_external_actions.label,
|
||||
npwd_emails_external_actions.close_phone,
|
||||
npwd_emails_external_actions.delete_email,
|
||||
npwd_emails_external_actions.event_name,
|
||||
npwd_emails_external_actions.event_arg
|
||||
FROM npwd_emails_external_actions
|
||||
WHERE message_id = ?;
|
||||
WHERE message_id = ?
|
||||
`;
|
||||
|
||||
const [phoneActions] = await pool.query(queryPhoneActions, [id]);
|
||||
const [externalActions] = await pool.query(queryExternalActions, [id]);
|
||||
|
||||
console.log({
|
||||
phoneActions: phoneActions as UnformattedEmailPhoneAction[],
|
||||
externalActions: externalActions as UnformattedEmailExternalAction[],
|
||||
});
|
||||
|
||||
return {
|
||||
phoneActions: phoneActions as UnformattedEmailPhoneAction[],
|
||||
externalActions: externalActions as UnformattedEmailExternalAction[],
|
||||
|
||||
@@ -106,7 +106,7 @@ onNet(EmailEvents.FETCH_MESSAGE_ACTIONS, async ({ messageId }: { messageId: numb
|
||||
const actions = await fetchMessageActions(messageId);
|
||||
const phoneActions = mapUnformattedEmailPhoneActions(actions.phoneActions);
|
||||
const externalActions = mapUnformattedEmailExternalActions(actions.externalActions);
|
||||
emitNet(EmailEvents.FETCH_MESSAGE_ACTIONS_SUCCESS, { phoneActions, externalActions });
|
||||
emitNet(EmailEvents.FETCH_MESSAGE_ACTIONS_SUCCESS, _source, { phoneActions, externalActions });
|
||||
} catch (e) {
|
||||
emailLogger.error(`Failed to fetch email message actions, ${e.message}`, {
|
||||
source: _source,
|
||||
|
||||
@@ -135,7 +135,10 @@ export async function generatePhoneNumber(identifier: string): Promise<string> {
|
||||
return phoneNumber;
|
||||
}
|
||||
|
||||
export async function generateEmail(identifier: string): Promise<string> {
|
||||
export async function generateEmail(
|
||||
identifier: string,
|
||||
cb?: (email: string) => void,
|
||||
): Promise<string> {
|
||||
const getQuery = `SELECT phone_email FROM users WHERE identifier = ?`;
|
||||
const [results] = await pool.query(getQuery, [identifier]);
|
||||
const result = <any[]>results;
|
||||
@@ -153,6 +156,7 @@ export async function generateEmail(identifier: string): Promise<string> {
|
||||
const newEmail = `${userProfileNames[0]}@${emailProvider}`.trim().toLowerCase();
|
||||
const query = 'UPDATE users SET phone_email = ? WHERE identifier = ?';
|
||||
await pool.query(query, [newEmail, identifier]);
|
||||
cb?.(newEmail);
|
||||
mainLogger.debug(`Inserting email into Database: ${newEmail}`);
|
||||
return newEmail;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ import { mainLogger } from '../sv_logger';
|
||||
import { pool } from '../db';
|
||||
import { generateEmail, generatePhoneNumber } from '../functions';
|
||||
import { PhoneEvents } from '../../../typings/phone';
|
||||
import { sendEmail } from './../email/sv_email';
|
||||
import config from '../../utils/config';
|
||||
|
||||
export const playerLogger = mainLogger.child({
|
||||
module: 'player',
|
||||
@@ -17,7 +19,7 @@ export async function handlePlayerAdd(pSource: number) {
|
||||
|
||||
// Parse specifically for license identifier as its
|
||||
// guranteed
|
||||
let playerIdentifer;
|
||||
let playerIdentifer: string = null;
|
||||
for (const identifier of playerIdentifiers) {
|
||||
if (identifier.includes('license:')) {
|
||||
playerIdentifer = identifier.split(':')[1];
|
||||
@@ -37,7 +39,23 @@ 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 email = await generateEmail(playerIdentifer, (email) => {
|
||||
sendEmail(
|
||||
'npwd',
|
||||
`no-reply@${config.email.provider || 'project-error.dev'}`,
|
||||
[
|
||||
{
|
||||
email,
|
||||
identifier: playerIdentifer,
|
||||
},
|
||||
],
|
||||
'--translate-APPS_EMAIL_WELCOME',
|
||||
'New Phone Who Dis',
|
||||
null,
|
||||
[{ href: '/settings', label: 'Go to Settings', deleteEmail: false, closePhone: false }],
|
||||
[],
|
||||
);
|
||||
});
|
||||
|
||||
const newPlayer = new Player({
|
||||
identifier: playerIdentifer,
|
||||
|
||||
Reference in new issue
Block a user