mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
working client/server intaction
This commit is contained in:
1 parent
c19d0ee3aa
commit
2920267ef3
8 files changed
+99
-58
No files matched your search
@@ -19,12 +19,6 @@ function sendTwitterMessage(method, data)
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
RegisterNetEvent('phone:fetchTweets')
|
|
||||||
AddEventHandler('phone:fetchTweets', function()
|
|
||||||
ESX.TriggerServerCallback('phone:fetchTweets', function(tweets)
|
|
||||||
sendTwitterMessage('fetchTweets', tweets)
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
|
|
||||||
RegisterNetEvent('phone:fetchTweetsFiltered')
|
RegisterNetEvent('phone:fetchTweetsFiltered')
|
||||||
AddEventHandler('phone:fetchTweetsFiltered', function(searchValue)
|
AddEventHandler('phone:fetchTweetsFiltered', function(searchValue)
|
||||||
@@ -34,9 +28,6 @@ AddEventHandler('phone:fetchTweetsFiltered', function(searchValue)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
RegisterNUICallback('phone:fetchTweets', function()
|
|
||||||
TriggerEvent('phone:fetchTweets')
|
|
||||||
end)
|
|
||||||
|
|
||||||
|
|
||||||
RegisterNUICallback('phone:fetchTweetsFiltered', function(searchValue)
|
RegisterNUICallback('phone:fetchTweetsFiltered', function(searchValue)
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import events from '../utils/events';
|
||||||
|
import { sendTwitterMessage } from '../utils/messages';
|
||||||
|
|
||||||
|
RegisterNuiCallbackType(events.TWITTER_FETCH_TWEETS);
|
||||||
|
on(`__cfx_nui:${events.TWITTER_FETCH_TWEETS}`, () => {
|
||||||
|
emitNet(events.TWITTER_FETCH_TWEETS);
|
||||||
|
});
|
||||||
|
|
||||||
|
onNet(events.TWITTER_FETCH_TWEETS_SUCCESS, (results: any) => {
|
||||||
|
sendTwitterMessage(events.TWITTER_FETCH_TWEETS_SUCCESS, results);
|
||||||
|
});
|
||||||
|
|
||||||
|
onNet(events.TWITTER_FETCH_TWEETS_FAILURE, () => {
|
||||||
|
sendTwitterMessage(events.TWITTER_FETCH_TWEETS_FAILURE);
|
||||||
|
});
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import {ESXClient} from "fivem-esx-js/client/esx_client";
|
import { ESXClient } from "fivem-esx-js/client/esx_client";
|
||||||
|
import './cl_twitter';
|
||||||
|
|
||||||
let ESX: ESXClient = null;
|
let ESX: ESXClient = null;
|
||||||
|
|
||||||
|
|||||||
@@ -51,16 +51,16 @@ function fetchTweetsFiltered(profileId, searchValue, cb)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
ESX.RegisterServerCallback('phone:fetchTweets', function(source, cb)
|
-- ESX.RegisterServerCallback('phone:fetchTweets', function(source, cb)
|
||||||
local _source = source
|
-- local _source = source
|
||||||
local xPlayer = ESX.GetPlayerFromId(_source)
|
-- local xPlayer = ESX.GetPlayerFromId(_source)
|
||||||
local _identifier = xPlayer.getIdentifier()
|
-- local _identifier = xPlayer.getIdentifier()
|
||||||
|
|
||||||
getProfile(_identifier, function(result)
|
-- getProfile(_identifier, function(result)
|
||||||
local profile = result[1]
|
-- local profile = result[1]
|
||||||
fetchAllTweets(profile.id, cb)
|
-- fetchAllTweets(profile.id, cb)
|
||||||
end)
|
-- end)
|
||||||
end)
|
-- end)
|
||||||
|
|
||||||
-- search value expected to be lower case
|
-- search value expected to be lower case
|
||||||
ESX.RegisterServerCallback('phone:fetchTweetsFiltered', function(source, cb, searchValue)
|
ESX.RegisterServerCallback('phone:fetchTweetsFiltered', function(source, cb, searchValue)
|
||||||
|
|||||||
@@ -1,46 +1,59 @@
|
|||||||
import { pool } from './db';
|
import { pool } from './db';
|
||||||
|
import events from '../utils/events';
|
||||||
|
|
||||||
async function fetchAllTweets(profileId: number) {
|
async function fetchAllTweets(profileId: number) {
|
||||||
try {
|
const query = `
|
||||||
const query = `
|
SELECT
|
||||||
SELECT
|
npwd_twitter_profiles.profile_name,
|
||||||
npwd_twitter_profiles.profile_name,
|
npwd_twitter_profiles.avatar_url,
|
||||||
npwd_twitter_profiles.avatar_url,
|
npwd_twitter_tweets.*,
|
||||||
npwd_twitter_tweets.*,
|
npwd_twitter_likes.id IS NOT NULL AS isLiked,
|
||||||
npwd_twitter_likes.id IS NOT NULL AS isLiked,
|
TIME_TO_SEC(TIMEDIFF( NOW(), npwd_twitter_tweets.createdAt)) AS seconds_since_tweet
|
||||||
TIME_TO_SEC(TIMEDIFF( NOW(), npwd_twitter_tweets.createdAt)) AS seconds_since_tweet
|
FROM npwd_twitter_tweets
|
||||||
FROM npwd_twitter_tweets
|
LEFT OUTER JOIN npwd_twitter_profiles ON npwd_twitter_tweets.identifier = npwd_twitter_profiles.identifier
|
||||||
LEFT OUTER JOIN npwd_twitter_profiles ON npwd_twitter_tweets.identifier = npwd_twitter_profiles.identifier
|
LEFT OUTER JOIN npwd_twitter_likes ON npwd_twitter_tweets.id = npwd_twitter_likes.tweet_id AND npwd_twitter_likes.profile_id = ?
|
||||||
LEFT OUTER JOIN npwd_twitter_likes ON npwd_twitter_tweets.id = npwd_twitter_likes.tweet_id AND npwd_twitter_likes.profile_id = ?
|
WHERE visible = 1
|
||||||
WHERE visible = 1
|
ORDER BY npwd_twitter_tweets.createdAt DESC
|
||||||
ORDER BY npwd_twitter_tweets.createdAt DESC
|
LIMIT 100
|
||||||
LIMIT 100
|
`;
|
||||||
`;
|
const [ results ] = await pool.query(query, [profileId]);
|
||||||
const [results ] = await pool.query(query, [profileId]);
|
return results;
|
||||||
} catch (e) {
|
|
||||||
console.warn(e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchTweetsFiltered(profileId: number, searchValue: string) {
|
async function fetchTweetsFiltered(profileId: number, searchValue: string) {
|
||||||
try {
|
const parameterizedSearchValue = `%${searchValue}%`;
|
||||||
const parameterizedSearchValue = `%${searchValue}%`;
|
const query = `
|
||||||
const query = `
|
SELECT
|
||||||
SELECT
|
npwd_twitter_profiles.profile_name,
|
||||||
npwd_twitter_profiles.profile_name,
|
npwd_twitter_profiles.avatar_url,
|
||||||
npwd_twitter_profiles.avatar_url,
|
npwd_twitter_tweets.*,
|
||||||
npwd_twitter_tweets.*,
|
npwd_twitter_likes.id IS NOT NULL AS isLiked,
|
||||||
npwd_twitter_likes.id IS NOT NULL AS isLiked,
|
TIME_TO_SEC(TIMEDIFF( NOW(), npwd_twitter_tweets.createdAt)) AS seconds_since_tweet
|
||||||
TIME_TO_SEC(TIMEDIFF( NOW(), npwd_twitter_tweets.createdAt)) AS seconds_since_tweet
|
FROM npwd_twitter_tweets
|
||||||
FROM npwd_twitter_tweets
|
LEFT OUTER JOIN npwd_twitter_profiles ON npwd_twitter_tweets.identifier = npwd_twitter_profiles.identifier
|
||||||
LEFT OUTER JOIN npwd_twitter_profiles ON npwd_twitter_tweets.identifier = npwd_twitter_profiles.identifier
|
LEFT OUTER JOIN npwd_twitter_likes ON npwd_twitter_tweets.id = npwd_twitter_likes.tweet_id AND npwd_twitter_likes.profile_id = ?
|
||||||
LEFT OUTER JOIN npwd_twitter_likes ON npwd_twitter_tweets.id = npwd_twitter_likes.tweet_id AND npwd_twitter_likes.profile_id = ?
|
WHERE visible = 1 AND (npwd_twitter_profiles.profile_name LIKE @profile_name OR npwd_twitter_tweets.message LIKE ?)
|
||||||
WHERE visible = 1 AND (npwd_twitter_profiles.profile_name LIKE @profile_name OR npwd_twitter_tweets.message LIKE ?)
|
ORDER BY npwd_twitter_tweets.createdAt DESC
|
||||||
ORDER BY npwd_twitter_tweets.createdAt DESC
|
LIMIT 100
|
||||||
LIMIT 100
|
`;
|
||||||
`;
|
const [ results ] = await pool.query(query, [profileId, parameterizedSearchValue]);
|
||||||
const [results ] = await pool.query(query, [profileId, parameterizedSearchValue]);
|
return results;
|
||||||
} catch (e) {
|
|
||||||
console.warn(e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getProfile(identifier: string) {
|
||||||
|
const query = `
|
||||||
|
SELECT * FROM npwd_twitter_profiles
|
||||||
|
WHERE identifier = ?
|
||||||
|
LIMIT 1
|
||||||
|
`;
|
||||||
|
const [results] = await pool.query(query, [identifier]);
|
||||||
|
}
|
||||||
|
|
||||||
|
onNet(events.TWITTER_FETCH_TWEETS, async () => {
|
||||||
|
try {
|
||||||
|
const results = await fetchAllTweets(24);
|
||||||
|
emitNet(events.TWITTER_FETCH_TWEETS_SUCCESS, source, results);
|
||||||
|
} catch (e) {
|
||||||
|
emitNet(events.TWITTER_FETCH_TWEETS_FAILURE, source);
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export default {
|
||||||
|
TWITTER: 'TWITTER',
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
export default {
|
||||||
|
TWITTER_FETCH_TWEETS: 'phone:fetchTweets',
|
||||||
|
TWITTER_FETCH_TWEETS_SUCCESS: 'fetchTweets',
|
||||||
|
TWITTER_FETCH_TWEETS_FAILURE: 'fetchTweetsFailed',
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import apps from './apps';
|
||||||
|
|
||||||
|
function sendMessage(app: string, method: string, data: any) {
|
||||||
|
return SendNuiMessage(JSON.stringify({
|
||||||
|
app,
|
||||||
|
method,
|
||||||
|
data,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sendTwitterMessage(method: string, data: any = {}) {
|
||||||
|
return sendMessage(apps.TWITTER, method, data);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user