Feature/Twitter Notification Filters (#147)

Feature: Twitter notification update
This commit is contained in:
Erik authored and GitHub committed 2021-03-07 16:25:10 +01:00
1 parent 21152fa38a
commit 0203ebbe51
15 files changed
+85 -23

No files matched your search

+8 -2
View File
@@ -2,7 +2,9 @@ import { ESX } from './server';
import { pool } from './db';
import config from '../utils/config';
import { getIdentifier, getIdentifierByPhoneNumber, getSource, usePhoneNumber } from './functions';
import { getOrCreateProfile } from './sv_twitter';
import { mainLogger } from './sv_logger';
import events from '../utils/events';
//db = DatabaseConfig //helper variable for use in server function
@@ -63,14 +65,18 @@ async function getCredentials(identifier: string): Promise<string> {
onNet('esx:playerLoaded', async (playerId: number, xPlayer: any) => {
const _source = getSource();
const identifier = xPlayer.identifier;
try {
const identifier = xPlayer.identifier;
await generatePhoneNumber(identifier);
} catch (e) {
mainLogger.error(`Failed to generate a phone number, ${e.message}`, {
source: _source,
});
}
// make sure a twitter profile exists for this user before
// we load the phone
await getOrCreateProfile(identifier);
});
onNet('phone:getCredentials', async () => {
@@ -84,4 +90,4 @@ onNet('phone:getCredentials', async () => {
source: _source,
});
}
});
});
+4 -2
View File
@@ -199,11 +199,12 @@ async function createDefaultProfile(identifier: string): Promise<Profile> {
* not, create it and return it.
* @param identifier - player's identifier
*/
async function getOrCreateProfile(identifier: string): Promise<Profile> {
export async function getOrCreateProfile(identifier: string): Promise<Profile> {
const profile = await getProfile(identifier);
return profile || (await createDefaultProfile(identifier));
}
async function updateProfile(identifier: string, profile: Profile) {
const { avatar_url, profile_name, bio, location, job } = profile;
const query = `
@@ -306,8 +307,9 @@ async function doesRetweetExist(tweetId: number, identifier: string): Promise<bo
onNet(events.TWITTER_GET_OR_CREATE_PROFILE, async () => {
const _source = getSource();
const identifier = getIdentifier(_source);
try {
const identifier = getIdentifier(_source);
const profile = await getOrCreateProfile(identifier);
emitNet(events.TWITTER_GET_OR_CREATE_PROFILE_SUCCESS, _source, profile);
} catch (e) {