mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
more formatting
This commit is contained in:
1 parent
046447b0fb
commit
f552c1212c
157 files changed
+635
-1579
No files matched your search
@@ -14,7 +14,7 @@ import { mainLogger } from './sv_logger';
|
||||
const mysqlConnectionString = GetConvar(CONNECTION_STRING, 'none');
|
||||
if (mysqlConnectionString === 'none') {
|
||||
const error = new Error(
|
||||
`No connection string provided. make sure "${CONNECTION_STRING}" is set in your config.`
|
||||
`No connection string provided. make sure "${CONNECTION_STRING}" is set in your config.`,
|
||||
);
|
||||
mainLogger.error(error.message);
|
||||
throw error;
|
||||
@@ -51,9 +51,7 @@ export function generateConnectionPool() {
|
||||
scheme: 'mysql',
|
||||
hosts: [],
|
||||
});
|
||||
const connectionOjbect = connectionStringParser.parse(
|
||||
mysqlConnectionString
|
||||
);
|
||||
const connectionOjbect = connectionStringParser.parse(mysqlConnectionString);
|
||||
|
||||
return mysql.createPool({
|
||||
host: connectionOjbect.hosts[0].host,
|
||||
@@ -84,9 +82,7 @@ export async function withTransaction(queries: Promise<any>[]): Promise<any[]> {
|
||||
await connection.release();
|
||||
return results;
|
||||
} catch (err) {
|
||||
mainLogger.warn(
|
||||
`Error when submitting queries in transaction, ${err.message}`
|
||||
);
|
||||
mainLogger.warn(`Error when submitting queries in transaction, ${err.message}`);
|
||||
await connection.rollback();
|
||||
await connection.release();
|
||||
return Promise.reject(err);
|
||||
|
||||
@@ -15,7 +15,7 @@ export function parseSemiColonFormat(connectionString: string): Map {
|
||||
const parts = connectionString.split(';');
|
||||
if (parts.length === 1) {
|
||||
throw new Error(
|
||||
`Connection string ${connectionString} is in the incorrect format. Please follow the README.`
|
||||
`Connection string ${connectionString} is in the incorrect format. Please follow the README.`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ const POST_CHANNEL_URL = `${BASE_URL}/channels/${DISCORD_CHANNEL_ID}/messages`;
|
||||
|
||||
export async function reportTweetToDiscord(
|
||||
tweet: Tweet,
|
||||
reportingProfile: Profile
|
||||
reportingProfile: Profile,
|
||||
): Promise<any> {
|
||||
if (!DISCORD_TOKEN || !DISCORD_CHANNEL_ID) {
|
||||
discordLogger.warn(`Got a request to report a tweet but discord is not
|
||||
@@ -26,9 +26,7 @@ export async function reportTweetToDiscord(
|
||||
}
|
||||
const content = `**REPORTED TWEET**
|
||||
----------------------------------------------------------------------
|
||||
**Reporting User**: ${reportingProfile.profile_name} (${
|
||||
reportingProfile.id
|
||||
})
|
||||
**Reporting User**: ${reportingProfile.profile_name} (${reportingProfile.id})
|
||||
**Reported User**: ${tweet.profile_name} (${tweet.profile_id})
|
||||
**Reported Tweet timestamp**: ${tweet.createdAt}
|
||||
----------------------------------------------------------------------
|
||||
@@ -40,9 +38,5 @@ export async function reportTweetToDiscord(
|
||||
${tweet.images.split(IMAGE_DELIMITER).join('\n')}
|
||||
`;
|
||||
|
||||
return await axios.post(
|
||||
POST_CHANNEL_URL,
|
||||
{ content },
|
||||
{ headers: DISCORD_HEADERS }
|
||||
);
|
||||
return await axios.post(POST_CHANNEL_URL, { content }, { headers: DISCORD_HEADERS });
|
||||
}
|
||||
@@ -22,9 +22,7 @@ export function getIdentifier(source: number): string {
|
||||
return ESX.GetPlayerFromId(source).getIdentifier();
|
||||
}
|
||||
|
||||
export async function getIdentifierByPhoneNumber(
|
||||
phoneNumber: string
|
||||
): Promise<string> {
|
||||
export async function getIdentifierByPhoneNumber(phoneNumber: string): Promise<string> {
|
||||
const query = 'SELECT identifier FROM users WHERE phone_number = ?';
|
||||
const [results] = await pool.query(query, [phoneNumber]);
|
||||
const identifier = <Identifier[]>results;
|
||||
|
||||
@@ -2,23 +2,19 @@ import events from '../utils/events';
|
||||
import { ESX } from './server';
|
||||
import { getSource } from './functions';
|
||||
import { pool } from './db';
|
||||
import {
|
||||
Transfer,
|
||||
IBankCredentials,
|
||||
} from '../../phone/src/common/typings/bank';
|
||||
import { Transfer, IBankCredentials } from '../../phone/src/common/typings/bank';
|
||||
import { getIdentifier } from './functions';
|
||||
import { mainLogger } from './sv_logger';
|
||||
|
||||
const bankLogger = mainLogger.child({ module: 'bank' });
|
||||
|
||||
async function fetchAllTransactions(identifier: string): Promise<Transfer[]> {
|
||||
const query =
|
||||
'SELECT * FROM npwd_bank_transfers WHERE identifier = ? ORDER BY id DESC';
|
||||
const query = 'SELECT * FROM npwd_bank_transfers WHERE identifier = ? ORDER BY id DESC';
|
||||
const [results] = await pool.query(query, [identifier]);
|
||||
const transactions = <Transfer[]>results;
|
||||
|
||||
bankLogger.verbose(
|
||||
`Fetched all transactions (${identifier}) - ${JSON.stringify(transactions)}`
|
||||
`Fetched all transactions (${identifier}) - ${JSON.stringify(transactions)}`,
|
||||
);
|
||||
|
||||
return transactions;
|
||||
@@ -38,10 +34,7 @@ function fetchCredentials(): IBankCredentials {
|
||||
return result;
|
||||
}
|
||||
|
||||
async function addTransfer(
|
||||
identifier: string,
|
||||
transfer: Transfer
|
||||
): Promise<any> {
|
||||
async function addTransfer(identifier: string, transfer: Transfer): Promise<any> {
|
||||
const xPlayer = ESX.GetPlayerFromId(getSource());
|
||||
const bankBalance = xPlayer.getAccount('bank').money;
|
||||
const sourceName = xPlayer.getName();
|
||||
|
||||
+60
-92
@@ -25,10 +25,7 @@ async function getPlayerFromIdentifier(identifier: string): Promise<XPlayer> {
|
||||
|
||||
for (const player of xPlayers) {
|
||||
const xPlayer = ESX.GetPlayerFromId(player);
|
||||
if (
|
||||
xPlayer.getIdentifier() != null &&
|
||||
xPlayer.getIdentifier() == identifier
|
||||
) {
|
||||
if (xPlayer.getIdentifier() != null && xPlayer.getIdentifier() == identifier) {
|
||||
res(xPlayer);
|
||||
}
|
||||
}
|
||||
@@ -40,17 +37,11 @@ async function getPlayerFromIdentifier(identifier: string): Promise<XPlayer> {
|
||||
async function saveCall(call: ICall) {
|
||||
const query =
|
||||
'INSERT INTO npwd_calls (identifier, transmitter, receiver, start) VALUES (?, ?, ?, ?)';
|
||||
await pool.query(query, [
|
||||
call.identifier,
|
||||
call.transmitter,
|
||||
call.receiver,
|
||||
call.start,
|
||||
]);
|
||||
await pool.query(query, [call.identifier, call.transmitter, call.receiver, call.start]);
|
||||
}
|
||||
|
||||
async function updateCall(call: ICall, isAccepted: boolean, end: number) {
|
||||
const query =
|
||||
'UPDATE npwd_calls SET is_accepted=?, end=? WHERE identifier = ?';
|
||||
const query = 'UPDATE npwd_calls SET is_accepted=?, end=? WHERE identifier = ?';
|
||||
await pool.query(query, [isAccepted, end, call.identifier]);
|
||||
}
|
||||
|
||||
@@ -64,57 +55,46 @@ async function fetchCalls(phoneNumber: string): Promise<ICall[]> {
|
||||
|
||||
let calls: Map<string, ICall> = new Map();
|
||||
|
||||
onNet(
|
||||
events.PHONE_INITIALIZE_CALL,
|
||||
async (phoneNumber: string, timestamp: number) => {
|
||||
const _source = getSource();
|
||||
onNet(events.PHONE_INITIALIZE_CALL, async (phoneNumber: string, timestamp: number) => {
|
||||
const _source = getSource();
|
||||
|
||||
const callIdentifier = uuidv4();
|
||||
const callIdentifier = uuidv4();
|
||||
|
||||
// the client that is calling
|
||||
const xTransmitter = ESX.GetPlayerFromId(_source);
|
||||
const transmitterNumber = await usePhoneNumber(
|
||||
xTransmitter.getIdentifier()
|
||||
);
|
||||
// the client that is calling
|
||||
const xTransmitter = ESX.GetPlayerFromId(_source);
|
||||
const transmitterNumber = await usePhoneNumber(xTransmitter.getIdentifier());
|
||||
|
||||
// player who is being called
|
||||
const receiverIdentifier = await getIdentifierByPhoneNumber(phoneNumber);
|
||||
const xReceiver = await getPlayerFromIdentifier(receiverIdentifier);
|
||||
const receiverNumber = phoneNumber;
|
||||
// player who is being called
|
||||
const receiverIdentifier = await getIdentifierByPhoneNumber(phoneNumber);
|
||||
const xReceiver = await getPlayerFromIdentifier(receiverIdentifier);
|
||||
const receiverNumber = phoneNumber;
|
||||
|
||||
calls.set(transmitterNumber, {
|
||||
identifier: callIdentifier,
|
||||
transmitter: transmitterNumber,
|
||||
transmitterSource: _source,
|
||||
receiver: receiverNumber,
|
||||
receiverSource: xReceiver.source,
|
||||
start: timestamp / 1000,
|
||||
accepted: false,
|
||||
});
|
||||
calls.set(transmitterNumber, {
|
||||
identifier: callIdentifier,
|
||||
transmitter: transmitterNumber,
|
||||
transmitterSource: _source,
|
||||
receiver: receiverNumber,
|
||||
receiverSource: xReceiver.source,
|
||||
start: timestamp / 1000,
|
||||
accepted: false,
|
||||
});
|
||||
|
||||
const currentCall = calls.get(transmitterNumber);
|
||||
await saveCall(currentCall);
|
||||
const currentCall = calls.get(transmitterNumber);
|
||||
await saveCall(currentCall);
|
||||
|
||||
// events
|
||||
// client that is calling
|
||||
emitNet(
|
||||
events.PHONE_START_CALL,
|
||||
_source,
|
||||
transmitterNumber,
|
||||
receiverNumber,
|
||||
true
|
||||
);
|
||||
// events
|
||||
// client that is calling
|
||||
emitNet(events.PHONE_START_CALL, _source, transmitterNumber, receiverNumber, true);
|
||||
|
||||
// client that is being called
|
||||
emitNet(
|
||||
events.PHONE_START_CALL,
|
||||
xReceiver.source,
|
||||
transmitterNumber,
|
||||
receiverNumber,
|
||||
false
|
||||
);
|
||||
}
|
||||
);
|
||||
// client that is being called
|
||||
emitNet(
|
||||
events.PHONE_START_CALL,
|
||||
xReceiver.source,
|
||||
transmitterNumber,
|
||||
receiverNumber,
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
onNet(events.PHONE_ACCEPT_CALL, async (transmitterNumber: string) => {
|
||||
const pSource = getSource();
|
||||
@@ -125,13 +105,7 @@ onNet(events.PHONE_ACCEPT_CALL, async (transmitterNumber: string) => {
|
||||
await updateCall(currentCall, true, null);
|
||||
|
||||
// player who is being called
|
||||
emitNet(
|
||||
events.PHONE_CALL_WAS_ACCEPTED,
|
||||
pSource,
|
||||
channelId,
|
||||
currentCall,
|
||||
false
|
||||
);
|
||||
emitNet(events.PHONE_CALL_WAS_ACCEPTED, pSource, channelId, currentCall, false);
|
||||
|
||||
// player who is calling
|
||||
emitNet(
|
||||
@@ -139,7 +113,7 @@ onNet(events.PHONE_ACCEPT_CALL, async (transmitterNumber: string) => {
|
||||
currentCall.transmitterSource,
|
||||
channelId,
|
||||
currentCall,
|
||||
true
|
||||
true,
|
||||
);
|
||||
|
||||
currentCall.accepted = true;
|
||||
@@ -167,39 +141,33 @@ onNet(
|
||||
source: pSource,
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
onNet(
|
||||
events.PHONE_END_CALL,
|
||||
async (transmitterNumber: string, timestamp: number) => {
|
||||
const pSource = getSource();
|
||||
try {
|
||||
const currentCall = calls.get(transmitterNumber);
|
||||
const endTime = timestamp / 1000;
|
||||
await updateCall(currentCall, false, endTime);
|
||||
const accepted = calls.get(pSource);
|
||||
onNet(events.PHONE_END_CALL, async (transmitterNumber: string, timestamp: number) => {
|
||||
const pSource = getSource();
|
||||
try {
|
||||
const currentCall = calls.get(transmitterNumber);
|
||||
const endTime = timestamp / 1000;
|
||||
await updateCall(currentCall, false, endTime);
|
||||
const accepted = calls.get(pSource);
|
||||
|
||||
// player who is being called
|
||||
emitNet(events.PHONE_CALL_WAS_ENDED, currentCall.receiverSource);
|
||||
// player who is calling
|
||||
emitNet(events.PHONE_CALL_WAS_ENDED, currentCall.transmitterSource);
|
||||
// ends animations if call is active
|
||||
if (currentCall.accepted) {
|
||||
emitNet(events.PHONE_CALL_SEND_HANGUP_ANIM, currentCall.receiverSource);
|
||||
emitNet(
|
||||
events.PHONE_CALL_SEND_HANGUP_ANIM,
|
||||
currentCall.transmitterSource
|
||||
);
|
||||
}
|
||||
calls.delete(transmitterNumber);
|
||||
} catch (e) {
|
||||
callLogger.error(`Error ending Phone Call, ${e.message}`, {
|
||||
source: pSource,
|
||||
});
|
||||
// player who is being called
|
||||
emitNet(events.PHONE_CALL_WAS_ENDED, currentCall.receiverSource);
|
||||
// player who is calling
|
||||
emitNet(events.PHONE_CALL_WAS_ENDED, currentCall.transmitterSource);
|
||||
// ends animations if call is active
|
||||
if (currentCall.accepted) {
|
||||
emitNet(events.PHONE_CALL_SEND_HANGUP_ANIM, currentCall.receiverSource);
|
||||
emitNet(events.PHONE_CALL_SEND_HANGUP_ANIM, currentCall.transmitterSource);
|
||||
}
|
||||
calls.delete(transmitterNumber);
|
||||
} catch (e) {
|
||||
callLogger.error(`Error ending Phone Call, ${e.message}`, {
|
||||
source: pSource,
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
onNet(events.PHONE_CALL_FETCH_CALLS, async () => {
|
||||
const _source = getSource();
|
||||
|
||||
@@ -29,23 +29,15 @@ async function addContact(
|
||||
identifier: string,
|
||||
number: string,
|
||||
display: string,
|
||||
avatar: string
|
||||
avatar: string,
|
||||
): Promise<any> {
|
||||
const query =
|
||||
'INSERT INTO npwd_phone_contacts (identifier, number, display, avatar) VALUES (?, ?, ?, ?)';
|
||||
|
||||
const [result] = await pool.query(query, [
|
||||
identifier,
|
||||
number,
|
||||
display,
|
||||
avatar,
|
||||
]);
|
||||
const [result] = await pool.query(query, [identifier, number, display, avatar]);
|
||||
}
|
||||
|
||||
async function updateContact(
|
||||
contact: Contacts,
|
||||
identifier: string
|
||||
): Promise<any> {
|
||||
async function updateContact(contact: Contacts, identifier: string): Promise<any> {
|
||||
const query =
|
||||
'UPDATE npwd_phone_contacts SET number = ?, display = ?, avatar = ? WHERE id = ? AND identifier = ?';
|
||||
await pool.query(query, [
|
||||
@@ -57,12 +49,8 @@ async function updateContact(
|
||||
]);
|
||||
}
|
||||
|
||||
async function deleteContact(
|
||||
contact: ContactId,
|
||||
identifier: string
|
||||
): Promise<any> {
|
||||
const query =
|
||||
'DELETE FROM npwd_phone_contacts WHERE id = ? AND identifier = ?';
|
||||
async function deleteContact(contact: ContactId, identifier: string): Promise<any> {
|
||||
const query = 'DELETE FROM npwd_phone_contacts WHERE id = ? AND identifier = ?';
|
||||
await pool.query(query, [contact.id, identifier]);
|
||||
}
|
||||
|
||||
@@ -99,7 +87,7 @@ onNet(
|
||||
source: _source,
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
onNet(events.CONTACTS_UPDATE_CONTACT, async (contact: Contacts) => {
|
||||
|
||||
@@ -3,15 +3,12 @@ import config from '../utils/config';
|
||||
import path from 'path';
|
||||
|
||||
// Needed to manually apply a color to componenent property of log
|
||||
const manualColorize = (strToColor: string): string =>
|
||||
`[\x1b[35m${strToColor}\x1b[0m]`;
|
||||
const manualColorize = (strToColor: string): string => `[\x1b[35m${strToColor}\x1b[0m]`;
|
||||
|
||||
// Format handler passed to winston
|
||||
const formatLogs = (log: winston.Logform.TransformableInfo): string => {
|
||||
if (log.module)
|
||||
return `${log.label} ${manualColorize(log.module)} [${log.level}]: ${
|
||||
log.message
|
||||
}`;
|
||||
return `${log.label} ${manualColorize(log.module)} [${log.level}]: ${log.message}`;
|
||||
|
||||
return `${log.label} [${log.level}]: ${log.message}`;
|
||||
};
|
||||
@@ -28,14 +25,14 @@ export const mainLogger = winston.createLogger({
|
||||
format: winston.format.combine(
|
||||
winston.format.errors({ stack: true }),
|
||||
winston.format.timestamp(),
|
||||
winston.format.json()
|
||||
winston.format.json(),
|
||||
),
|
||||
}),
|
||||
new winston.transports.Console({
|
||||
format: winston.format.combine(
|
||||
winston.format.label({ label: '[NPWD]' }),
|
||||
winston.format.colorize({ all: true }),
|
||||
winston.format.printf(formatLogs)
|
||||
winston.format.printf(formatLogs),
|
||||
),
|
||||
}),
|
||||
],
|
||||
|
||||
@@ -49,7 +49,7 @@ interface MessageGroupMapping {
|
||||
async function createMessage(
|
||||
userIdentifier: string,
|
||||
groupId: string,
|
||||
message: string
|
||||
message: string,
|
||||
): Promise<any> {
|
||||
const query = `
|
||||
INSERT INTO npwd_messages
|
||||
@@ -66,7 +66,7 @@ async function createMessage(
|
||||
* @param userIdentifier - identifier of the user to get message groups for
|
||||
*/
|
||||
async function getMessageGroups(
|
||||
userIdentifier: string
|
||||
userIdentifier: string,
|
||||
): Promise<UnformattedMessageGroup[]> {
|
||||
const query = `
|
||||
SELECT
|
||||
@@ -104,10 +104,7 @@ async function getMessageGroups(
|
||||
* @param userIdentifier - user to get messages for
|
||||
* @param groupId - the group to get messages from
|
||||
*/
|
||||
async function getMessages(
|
||||
userIdentifier: string,
|
||||
groupId: string
|
||||
): Promise<Message[]> {
|
||||
async function getMessages(userIdentifier: string, groupId: string): Promise<Message[]> {
|
||||
const query = `
|
||||
SELECT
|
||||
npwd_messages.id,
|
||||
@@ -142,7 +139,7 @@ async function getMessages(
|
||||
async function createLabel(
|
||||
userIdentifier: string,
|
||||
groupId: string,
|
||||
label: string
|
||||
label: string,
|
||||
): Promise<any> {
|
||||
const query = `
|
||||
INSERT INTO npwd_messages_labels
|
||||
@@ -162,7 +159,7 @@ async function createLabel(
|
||||
async function createMessageGroup(
|
||||
userIdentifier: string,
|
||||
groupId: string,
|
||||
participantIdentifier: string
|
||||
participantIdentifier: string,
|
||||
): Promise<any> {
|
||||
const query = `
|
||||
INSERT INTO npwd_messages_groups
|
||||
@@ -180,9 +177,7 @@ async function createMessageGroup(
|
||||
* Find a players identifier from their phone number
|
||||
* @param phoneNumber - the phone number to search for
|
||||
*/
|
||||
async function getIdentifierFromPhoneNumber(
|
||||
phoneNumber: string
|
||||
): Promise<string> {
|
||||
async function getIdentifierFromPhoneNumber(phoneNumber: string): Promise<string> {
|
||||
const query = `
|
||||
SELECT identifier
|
||||
FROM users
|
||||
@@ -231,39 +226,34 @@ async function getMessageCountByGroup(groupId: string): Promise<number> {
|
||||
* @param userIdentifier - the user identifier to get message groups for
|
||||
*/
|
||||
async function getConsolidatedMessageGroups(
|
||||
userIdentifier: string
|
||||
userIdentifier: string,
|
||||
): Promise<MessageGroupMapping> {
|
||||
const messageGroups = await getMessageGroups(userIdentifier);
|
||||
return messageGroups.reduce(
|
||||
(mapping: MessageGroupMapping, messageGroup: UnformattedMessageGroup) => {
|
||||
const groupId = messageGroup.group_id;
|
||||
const displayTerm =
|
||||
messageGroup.display || messageGroup.phone_number || '???';
|
||||
const displayTerm = messageGroup.display || messageGroup.phone_number || '???';
|
||||
|
||||
if (groupId in mapping) {
|
||||
mapping[groupId].participants = mapping[groupId].participants.concat(
|
||||
displayTerm
|
||||
);
|
||||
mapping[groupId].participants = mapping[groupId].participants.concat(displayTerm);
|
||||
} else {
|
||||
mapping[groupId] = {
|
||||
user_identifier: messageGroup.user_identifier,
|
||||
avatar: messageGroup.avatar,
|
||||
label: messageGroup.label,
|
||||
participants: [displayTerm],
|
||||
updatedAt: messageGroup.updatedAt
|
||||
? messageGroup.updatedAt.toString()
|
||||
: null,
|
||||
updatedAt: messageGroup.updatedAt ? messageGroup.updatedAt.toString() : null,
|
||||
};
|
||||
}
|
||||
return mapping;
|
||||
},
|
||||
{}
|
||||
{},
|
||||
);
|
||||
}
|
||||
|
||||
async function getGroupIds(
|
||||
userIdentifier: string,
|
||||
groupMapping: MessageGroupMapping
|
||||
groupMapping: MessageGroupMapping,
|
||||
): Promise<string[]> {
|
||||
const groupIds: string[] = [];
|
||||
for (const groupId of Object.keys(groupMapping)) {
|
||||
@@ -281,7 +271,7 @@ async function getGroupIds(
|
||||
* @param userIdentifier - user to generate the MessageGroups for
|
||||
*/
|
||||
async function getFormattedMessageGroups(
|
||||
userIdentifier: string
|
||||
userIdentifier: string,
|
||||
): Promise<MessageGroup[]> {
|
||||
const groupMapping = await getConsolidatedMessageGroups(userIdentifier);
|
||||
const groupIds = await getGroupIds(userIdentifier, groupMapping);
|
||||
@@ -335,7 +325,7 @@ function createGroupHashID(identifiers: string[]) {
|
||||
async function createMessageGroupsFromPhoneNumbers(
|
||||
userIdentifier: string,
|
||||
phoneNumbers: string[],
|
||||
groupLabel: string
|
||||
groupLabel: string,
|
||||
): Promise<CreateMessageGroupResult> {
|
||||
// we check that each phoneNumber exists before we create the group
|
||||
const identifiers: string[] = [];
|
||||
@@ -363,7 +353,7 @@ async function createMessageGroupsFromPhoneNumbers(
|
||||
// other players works as expected
|
||||
createMessageGroup(userIdentifier, groupId, userIdentifier),
|
||||
...identifiers.map((identifier) =>
|
||||
createMessageGroup(userIdentifier, groupId, identifier)
|
||||
createMessageGroup(userIdentifier, groupId, identifier),
|
||||
),
|
||||
];
|
||||
|
||||
@@ -389,11 +379,7 @@ onNet(events.MESSAGES_FETCH_MESSAGE_GROUPS, async () => {
|
||||
try {
|
||||
const identifier = getIdentifier(_source);
|
||||
const messageGroups = await getFormattedMessageGroups(identifier);
|
||||
emitNet(
|
||||
events.MESSAGES_FETCH_MESSAGE_GROUPS_SUCCESS,
|
||||
_source,
|
||||
messageGroups
|
||||
);
|
||||
emitNet(events.MESSAGES_FETCH_MESSAGE_GROUPS_SUCCESS, _source, messageGroups);
|
||||
} catch (e) {
|
||||
emitNet(events.MESSAGES_FETCH_MESSAGE_GROUPS_FAILED, _source);
|
||||
messageLogger.error(`Failed to fetch messages groups, ${e.message}`);
|
||||
@@ -409,7 +395,7 @@ onNet(
|
||||
const result = await createMessageGroupsFromPhoneNumbers(
|
||||
_identifier,
|
||||
phoneNumbers,
|
||||
label
|
||||
label,
|
||||
);
|
||||
|
||||
if (result.error && result.duplicate) {
|
||||
@@ -452,7 +438,7 @@ onNet(
|
||||
source: _source,
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
onNet(events.MESSAGES_FETCH_MESSAGES, async (groupId: string) => {
|
||||
@@ -469,28 +455,25 @@ onNet(events.MESSAGES_FETCH_MESSAGES, async (groupId: string) => {
|
||||
}
|
||||
});
|
||||
|
||||
onNet(
|
||||
events.MESSAGES_SEND_MESSAGE,
|
||||
async (groupId: string, message: string) => {
|
||||
const _source = getSource();
|
||||
try {
|
||||
const _identifier = getIdentifier(_source);
|
||||
await createMessage(_identifier, groupId, message);
|
||||
emitNet(events.MESSAGES_SEND_MESSAGE_SUCCESS, _source, groupId);
|
||||
} catch (e) {
|
||||
// Not really sure what this does? As I cant find any reference
|
||||
// of this in the ui part.
|
||||
emitNet(events.MESSAGES_SEND_MESSAGE_FAILED, _source);
|
||||
// sending a new alert
|
||||
// The message property is always using the locale strings without
|
||||
// the APPS_ prefix.
|
||||
emitNet(events.MESSAGES_ACTION_RESULT, _source, {
|
||||
message: 'MESSAGES_NEW_MESSAGE_FAILED',
|
||||
type: 'error',
|
||||
});
|
||||
messageLogger.error(`Failed to send message, ${e.message}`, {
|
||||
source: _source,
|
||||
});
|
||||
}
|
||||
onNet(events.MESSAGES_SEND_MESSAGE, async (groupId: string, message: string) => {
|
||||
const _source = getSource();
|
||||
try {
|
||||
const _identifier = getIdentifier(_source);
|
||||
await createMessage(_identifier, groupId, message);
|
||||
emitNet(events.MESSAGES_SEND_MESSAGE_SUCCESS, _source, groupId);
|
||||
} catch (e) {
|
||||
// Not really sure what this does? As I cant find any reference
|
||||
// of this in the ui part.
|
||||
emitNet(events.MESSAGES_SEND_MESSAGE_FAILED, _source);
|
||||
// sending a new alert
|
||||
// The message property is always using the locale strings without
|
||||
// the APPS_ prefix.
|
||||
emitNet(events.MESSAGES_ACTION_RESULT, _source, {
|
||||
message: 'MESSAGES_NEW_MESSAGE_FAILED',
|
||||
type: 'error',
|
||||
});
|
||||
messageLogger.error(`Failed to send message, ${e.message}`, {
|
||||
source: _source,
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
@@ -7,14 +7,12 @@ import { mainLogger } from './sv_logger';
|
||||
const notesLogger = mainLogger.child({ module: 'notes' });
|
||||
|
||||
async function addNote(identifier: string, note: Note): Promise<any> {
|
||||
const query =
|
||||
'INSERT INTO npwd_notes (identifier, title, content) VALUES (?, ?, ?)';
|
||||
const query = 'INSERT INTO npwd_notes (identifier, title, content) VALUES (?, ?, ?)';
|
||||
await pool.query(query, [identifier, note.title, note.content]);
|
||||
}
|
||||
|
||||
async function fetchAllNotes(identifier: string): Promise<Note[]> {
|
||||
const query =
|
||||
'SELECT * FROM npwd_notes WHERE identifier = ? ORDER BY id DESC';
|
||||
const query = 'SELECT * FROM npwd_notes WHERE identifier = ? ORDER BY id DESC';
|
||||
const [result] = await pool.query(query, [identifier]);
|
||||
return <Note[]>result;
|
||||
}
|
||||
|
||||
@@ -7,8 +7,7 @@ import { mainLogger } from './sv_logger';
|
||||
const photoLogger = mainLogger.child({ module: 'photo' });
|
||||
|
||||
async function uploadPhoto(identifier: string, image: string) {
|
||||
const query =
|
||||
'INSERT INTO npwd_phone_gallery (identifier, image) VALUES (?, ?)';
|
||||
const query = 'INSERT INTO npwd_phone_gallery (identifier, image) VALUES (?, ?)';
|
||||
await pool.query(query, [identifier, image]);
|
||||
}
|
||||
|
||||
@@ -21,8 +20,7 @@ async function getPhotosByIdentifier(identifier: string): Promise<IPhoto[]> {
|
||||
}
|
||||
|
||||
async function deletePhoto(photo: IPhoto, identifier: string) {
|
||||
const query =
|
||||
'DELETE FROM npwd_phone_gallery WHERE image = ? AND identifier = ?';
|
||||
const query = 'DELETE FROM npwd_phone_gallery WHERE image = ? AND identifier = ?';
|
||||
await pool.query(query, [photo.image, identifier]);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ async function addListing(
|
||||
identifier: string,
|
||||
name: string,
|
||||
number: any,
|
||||
listing: MarketplaceListing
|
||||
listing: MarketplaceListing,
|
||||
): Promise<void> {
|
||||
const query =
|
||||
'INSERT INTO npwd_sellout_listings (identifier, name, number, title, url, description) VALUES (?, ?, ?, ?, ?, ?)';
|
||||
|
||||
@@ -51,7 +51,7 @@ async function fetchAllTweets(profileId: number): Promise<Tweet[]> {
|
||||
*/
|
||||
async function fetchTweetsFiltered(
|
||||
profileId: number,
|
||||
searchValue: string
|
||||
searchValue: string,
|
||||
): Promise<Tweet[]> {
|
||||
const parameterizedSearchValue = `%${searchValue}%`;
|
||||
const query = `
|
||||
@@ -116,19 +116,12 @@ async function createTweet(identifier: string, tweet: Tweet): Promise<Tweet> {
|
||||
INSERT INTO npwd_twitter_tweets (identifier, message, images)
|
||||
VALUES (?, ?, ?)
|
||||
`;
|
||||
const [results] = await pool.query(query, [
|
||||
identifier,
|
||||
tweet.message,
|
||||
tweet.images,
|
||||
]);
|
||||
const [results] = await pool.query(query, [identifier, tweet.message, tweet.images]);
|
||||
const insertData = <any>results;
|
||||
return await getTweet(profile.id, insertData.insertId);
|
||||
}
|
||||
|
||||
async function createTweetReport(
|
||||
tweetId: number,
|
||||
profileId: number
|
||||
): Promise<void> {
|
||||
async function createTweetReport(tweetId: number, profileId: number): Promise<void> {
|
||||
const query = `
|
||||
INSERT INTO npwd_twitter_reports (tweet_id, profile_id)
|
||||
VALUES (?, ?)
|
||||
@@ -203,14 +196,7 @@ async function updateProfile(identifier: string, profile: Profile) {
|
||||
SET avatar_url = ?, profile_name = ?, bio = ?, location = ?, job = ?
|
||||
WHERE identifier = ?
|
||||
`;
|
||||
await pool.execute(query, [
|
||||
avatar_url,
|
||||
profile_name,
|
||||
bio,
|
||||
location,
|
||||
job,
|
||||
identifier,
|
||||
]);
|
||||
await pool.execute(query, [avatar_url, profile_name, bio, location, job, identifier]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -259,10 +245,7 @@ async function deleteTweet(identifier: string, tweetId: number): Promise<void> {
|
||||
* @param profileId - primary key of the profile to check
|
||||
* @param tweetId - primary key of the tweet to check
|
||||
*/
|
||||
async function doesLikeExist(
|
||||
profileId: number,
|
||||
tweetId: number
|
||||
): Promise<boolean> {
|
||||
async function doesLikeExist(profileId: number, tweetId: number): Promise<boolean> {
|
||||
const query = `
|
||||
SELECT * FROM npwd_twitter_likes
|
||||
WHERE profile_id = ? AND tweet_id = ?
|
||||
@@ -278,10 +261,7 @@ async function doesLikeExist(
|
||||
* @param tweetId - primary key of the tweet to check
|
||||
* @param profileId - primary key of the profile to check
|
||||
*/
|
||||
async function doesReportExist(
|
||||
tweetId: number,
|
||||
profileId: number
|
||||
): Promise<boolean> {
|
||||
async function doesReportExist(tweetId: number, profileId: number): Promise<boolean> {
|
||||
const query = `
|
||||
SELECT * FROM npwd_twitter_reports
|
||||
WHERE tweet_id = ? AND profile_id = ?
|
||||
|
||||
Reference in new issue
Block a user