mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-03 14:38:45 +00:00
working tweet deletion
This commit is contained in:
1 parent
73272a6a43
commit
c0dbf1a765
11 files changed
+200
-14
No files matched your search
@@ -19,11 +19,12 @@ Below is the list of configuration options:
|
||||
| RunRate | 10 | interval in seconds to check phone destruction |
|
||||
| DestoryChance | 100 | Percent chance that phone destruction will occur |
|
||||
| DestroyPhoneReCheck | 3 | Time in minutes before another phone destruction attempt will happen |
|
||||
| notificationPosition.horizontal | right | Horizontal position of phone notifications. `left`, `center` or `right` |
|
||||
| notificationPosition.vertical | bottom | Vertical positon of phone notifications. `top` or `bottom` |
|
||||
| notificationPosition.horizontal | right | Horizontal position of phone notifications. `left`, `center` or `right` |
|
||||
| notificationPosition.vertical | bottom | Vertical positon of phone notifications. `top` or `bottom` |
|
||||
| twitter.showNotifications | true | Whether or not to show twitter notifications |
|
||||
| twitter.generateProfileNameFromUsers | true | Whether or not the server should automtically generate a player's profile name from their user in the database |
|
||||
| twitter.allowEdtiableProfileName | true | Whether or not players can edit their profile name |
|
||||
| twitter.allowDeleteTweets | true | Whether or not players can delete their own tweets |
|
||||
| twitter.characterLimit | 240 | Limit on how many characters tweets can contain |
|
||||
| twitter.enableAvatars | true | Whether or not player's can select avatars for their twitter profile |
|
||||
| twitter.enableEmojis | true | Whether or not player's can use emojis in tweets |
|
||||
|
||||
@@ -2,6 +2,7 @@ interface TwitterConfig {
|
||||
showNotifications: boolean;
|
||||
generateProfileNameFromUsers: boolean;
|
||||
allowEdtiableProfileName: boolean;
|
||||
allowDeleteTweets: boolean;
|
||||
characterLimit: number;
|
||||
enableAvatars: boolean;
|
||||
enableEmojis: boolean;
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
"showNotifications": true,
|
||||
"generateProfileNameFromUsers": true,
|
||||
"allowEdtiableProfileName": true,
|
||||
"allowDeleteTweets": true,
|
||||
"characterLimit": 240,
|
||||
"enableAvatars": true,
|
||||
"enableEmojis": true,
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
import React, { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
Button,
|
||||
Menu,
|
||||
MenuItem
|
||||
} from "@material-ui/core";
|
||||
import MoreIcon from "@material-ui/icons/MoreVert";
|
||||
import { usePhone } from "../../../../os/phone/hooks/usePhone";
|
||||
import Nui from "../../../../os/nui-events/utils/Nui";
|
||||
|
||||
|
||||
/**
|
||||
* Ok this is some bullshit. Due to either scaling issues or the NUI
|
||||
* overlay being different than the display resolution just letting
|
||||
* material-ui determine what the anchor positioning of the popover
|
||||
* is not reliable and has some error that appears to scale vertically.
|
||||
*
|
||||
* This vertical offset raises the popover positioning implementing the
|
||||
* transformOrigin prop that material-ui's Popover element provides.
|
||||
*
|
||||
* These coefficients are NOT based on any known offsets or calc()
|
||||
* functions. They are empiricallly determined. The actual scaling issue
|
||||
* does NOT appear to be linear, but over the comparatively low height
|
||||
* of the phone compared to the window it produces results that are within
|
||||
* acceptable tolerances from the player's perspective.
|
||||
* @param top - the computed distance from the top of the window to the top
|
||||
* of the anchor element
|
||||
*/
|
||||
function calculateVerticalOffset(top: number): number {
|
||||
return top * 0.20 - 38;
|
||||
}
|
||||
|
||||
export const ShowMore = ({ id, isMine }) => {
|
||||
const [anchorEl, setAnchorEl] = useState<Element | null>(null);
|
||||
const [verticalOffset, setVerticalOffset] = useState(0);
|
||||
const { t } = useTranslation();
|
||||
const { config } = usePhone();
|
||||
|
||||
if (!config) return null;
|
||||
|
||||
const handleClick = (event: React.MouseEvent) => {
|
||||
const element = event.currentTarget
|
||||
setAnchorEl(element);
|
||||
|
||||
const top = window.pageYOffset + element.getBoundingClientRect().top
|
||||
setVerticalOffset(calculateVerticalOffset(top));
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
setAnchorEl(null);
|
||||
setVerticalOffset(0);
|
||||
};
|
||||
|
||||
const handleDeleteTweet = () => {
|
||||
Nui.send("phone:deleteTweet", id);
|
||||
handleClose();
|
||||
}
|
||||
|
||||
const allowedToDelete = config.twitter.allowDeleteTweets && isMine;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button aria-controls="simple-menu" aria-haspopup="true" onClick={handleClick} >
|
||||
<MoreIcon />
|
||||
</Button>
|
||||
<Menu
|
||||
id="simple-menu"
|
||||
anchorEl={anchorEl}
|
||||
keepMounted
|
||||
open={Boolean(anchorEl)}
|
||||
onClose={handleClose}
|
||||
transformOrigin={{
|
||||
vertical: verticalOffset,
|
||||
horizontal: 'left'
|
||||
}}
|
||||
>
|
||||
{allowedToDelete && <MenuItem onClick={handleDeleteTweet}>{t('APPS_TWITTER_DELETE')}</MenuItem >}
|
||||
<MenuItem onClick={handleClose}>{t('APPS_TWITTER_REPORT')}</MenuItem >
|
||||
</Menu>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default ShowMore;
|
||||
@@ -1,22 +1,27 @@
|
||||
import React from "react";
|
||||
import React, { useState, memo } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { makeStyles } from "@material-ui/core/styles";
|
||||
import {
|
||||
ListItemAvatar,
|
||||
Avatar as MuiAvatar,
|
||||
Button,
|
||||
List,
|
||||
ListItem,
|
||||
ListItemText,
|
||||
Paper,
|
||||
Typography,
|
||||
} from "@material-ui/core";
|
||||
import MoreIcon from "@material-ui/icons/MoreVert";
|
||||
|
||||
import { ListItem } from "../../../../ui/components/ListItem";
|
||||
import { secondsToHumanReadable } from "../../utils/time";
|
||||
import LikeButton from "../buttons/LikeButton";
|
||||
import ReplyButton from "../buttons/ReplyButton";
|
||||
import ImageDisplay from "../images/ImageDisplay";
|
||||
import Avatar from "../Avatar";
|
||||
import ShowMore from './ShowMore';
|
||||
import { QuoteButton } from "../buttons/QuoteButton";
|
||||
import { usePhone } from "../../../../os/phone/hooks/usePhone";
|
||||
import Nui from "../../../../os/nui-events/utils/Nui";
|
||||
|
||||
const useStyles = makeStyles(() => ({
|
||||
root: {
|
||||
@@ -58,7 +63,7 @@ const useStyles = makeStyles(() => ({
|
||||
width: "100%",
|
||||
marginLeft: "-20px", // easier to do this here than override the MUI styles
|
||||
marginTop: "3px",
|
||||
},
|
||||
}
|
||||
}));
|
||||
|
||||
export const Tweet = (tweet) => {
|
||||
@@ -70,6 +75,7 @@ export const Tweet = (tweet) => {
|
||||
profile_name,
|
||||
seconds_since_tweet,
|
||||
isLiked,
|
||||
isMine,
|
||||
} = tweet;
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
@@ -81,7 +87,6 @@ export const Tweet = (tweet) => {
|
||||
// this is a workaround to transfer string new lines and returns that
|
||||
// are stored into the database into html for the UI to render
|
||||
const formattedMessage = message.replace(/\n\r?/g, "<br />");
|
||||
|
||||
const profileName = profile_name ? `@${profile_name}` : "";
|
||||
|
||||
return (
|
||||
@@ -114,13 +119,11 @@ export const Tweet = (tweet) => {
|
||||
<ReplyButton profile_name={profile_name} />
|
||||
<LikeButton tweetId={id} isLiked={isLiked} />
|
||||
<QuoteButton message={message} />
|
||||
<Button>
|
||||
<MoreIcon />
|
||||
</Button>
|
||||
<ShowMore isMine={isMine} id={id} />
|
||||
</div>
|
||||
</div>
|
||||
</ListItem>
|
||||
);
|
||||
};
|
||||
|
||||
export default Tweet;
|
||||
export default memo(Tweet);
|
||||
@@ -20,6 +20,8 @@
|
||||
"APPS_TWITTER_SUBMIT_IMAGE": "Add Media",
|
||||
"APPS_TWITTER_CLOSE_IMAGE": "Close",
|
||||
"APPS_TWITTER_CLOSE": "Close",
|
||||
"APPS_TWITTER_DELETE": "Delete",
|
||||
"APPS_TWITTER_REPORT": "Report",
|
||||
"APPS_TWITTER_JUST_NOW": "Just now",
|
||||
"APPS_TWITTER_SEARCH_TWEETS": "Search for tweets",
|
||||
"APPS_TWITTER_SEARCH_TWEETS_PLACEHOLDER": "Search by profile name or message",
|
||||
|
||||
@@ -3,6 +3,7 @@ interface TwitterConfig {
|
||||
generateProfileNameFromUsers: boolean;
|
||||
characterLimit: number;
|
||||
allowEdtiableProfileName: boolean;
|
||||
allowDeleteTweets: boolean;
|
||||
enableAvatars: boolean;
|
||||
enableEmojis: boolean;
|
||||
enableImages: boolean;
|
||||
|
||||
@@ -88,6 +88,23 @@ onNet(events.TWITTER_CREATE_TWEET_BROADCAST, (tweet: any) => {
|
||||
sendTwitterMessage(events.TWITTER_CREATE_TWEET_BROADCAST, tweet);
|
||||
});
|
||||
|
||||
/**
|
||||
* Twitter delete tweet
|
||||
*/
|
||||
RegisterNuiCallbackType(events.TWITTER_DELETE_TWEET);
|
||||
on(`__cfx_nui:${events.TWITTER_DELETE_TWEET}`, (tweetId: number) => {
|
||||
emitNet(events.TWITTER_DELETE_TWEET, tweetId);
|
||||
});
|
||||
|
||||
onNet(events.TWITTER_DELETE_TWEET_SUCCESS, () => {
|
||||
sendTwitterMessage(events.TWITTER_DELETE_TWEET_SUCCESS);
|
||||
emitNet(events.TWITTER_FETCH_TWEETS);
|
||||
});
|
||||
|
||||
onNet(events.TWITTER_DELETE_TWEET_FAILURE, () => {
|
||||
sendTwitterMessage(events.TWITTER_DELETE_TWEET_FAILURE);
|
||||
});
|
||||
|
||||
/**
|
||||
* Twitter likes
|
||||
*/
|
||||
|
||||
@@ -1 +1,44 @@
|
||||
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="%PUBLIC_URL%/favicon.ico"/><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"/><link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><title>React App</title></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script src="main.js"></script></body></html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" />
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Web site created using create-react-app"
|
||||
/>
|
||||
<!--
|
||||
manifest.json provides metadata used when your web app is installed on a
|
||||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||
-->
|
||||
|
||||
<!--
|
||||
Notice the use of in the tags above.
|
||||
It will be replaced with the URL of the `public` folder during the build.
|
||||
Only files inside the `public` folder can be referenced from the HTML.
|
||||
|
||||
Unlike "/favicon.ico" or "favicon.ico", "/favicon.ico" will
|
||||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>React App</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
<!--
|
||||
This HTML file is a template.
|
||||
If you open it directly in the browser, you will see an empty page.
|
||||
|
||||
You can add webfonts, meta tags, or analytics to this file.
|
||||
The build step will place the bundled scripts into the <body> tag.
|
||||
|
||||
To begin the development, run `npm start` or `yarn start`.
|
||||
To create a production bundle, use `npm run build` or `yarn build`.
|
||||
-->
|
||||
<script src="dev.js"></script></body>
|
||||
</html>
|
||||
@@ -21,6 +21,7 @@ interface ProfileName {
|
||||
|
||||
interface Tweet {
|
||||
id: number;
|
||||
profile_id?: number;
|
||||
profile_name?: string;
|
||||
avatar_url?: string;
|
||||
message: string;
|
||||
@@ -37,6 +38,7 @@ interface Tweet {
|
||||
async function fetchAllTweets(profileId: number): Promise<Tweet[]> {
|
||||
const query = `
|
||||
SELECT
|
||||
npwd_twitter_profiles.id AS profile_id,
|
||||
npwd_twitter_profiles.profile_name,
|
||||
npwd_twitter_profiles.avatar_url,
|
||||
npwd_twitter_tweets.*,
|
||||
@@ -51,7 +53,7 @@ async function fetchAllTweets(profileId: number): Promise<Tweet[]> {
|
||||
`;
|
||||
const [results] = await pool.query(query, [profileId]);
|
||||
const tweets = <Tweet[]>results;
|
||||
return tweets;
|
||||
return tweets.map(tweet => ({ ...tweet, isMine: tweet.profile_id === profileId}));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,6 +69,7 @@ async function fetchTweetsFiltered(
|
||||
const parameterizedSearchValue = `%${searchValue}%`;
|
||||
const query = `
|
||||
SELECT
|
||||
npwd_twitter_profiles.id AS profile_id,
|
||||
npwd_twitter_profiles.profile_name,
|
||||
npwd_twitter_profiles.avatar_url,
|
||||
npwd_twitter_tweets.*,
|
||||
@@ -85,7 +88,7 @@ async function fetchTweetsFiltered(
|
||||
parameterizedSearchValue,
|
||||
]);
|
||||
const tweets = <Tweet[]>results;
|
||||
return tweets;
|
||||
return tweets.map(tweet => ({ ...tweet, isMine: tweet.profile_id === profileId}));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,7 +156,7 @@ async function generateProfileName(identifier: string): Promise<string> {
|
||||
const profileNames = <ProfileName[]>results;
|
||||
|
||||
if (profileNames.length === 0) return defaultProfileName;
|
||||
return profileNames[0].profile_name;
|
||||
return profileNames[0].profile_name || defaultProfileName;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -224,6 +227,21 @@ async function deleteLike(profileId: number, tweetId: number): Promise<void> {
|
||||
await pool.execute(query, [profileId, tweetId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a tweet from the database
|
||||
* @param identifier - identifier of the source user
|
||||
* @param tweetId - primary key of the tweet to remove the like from
|
||||
*/
|
||||
async function deleteTweet(identifier: string, tweetId: number): Promise<void> {
|
||||
if (!config.twitter.allowDeleteTweets) return;
|
||||
|
||||
const query = `
|
||||
DELETE FROM npwd_twitter_tweets
|
||||
WHERE identifier = ? AND id = ?
|
||||
`;
|
||||
const [ result ] = await pool.execute(query, [identifier, tweetId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a "like" relationship between a profile and a tweet exists
|
||||
* @param profileId - primary key of the profile to check
|
||||
@@ -297,6 +315,17 @@ onNet(events.TWITTER_CREATE_TWEET, async (tweet: Tweet) => {
|
||||
}
|
||||
});
|
||||
|
||||
onNet(events.TWITTER_DELETE_TWEET, async (tweetId: number) => {
|
||||
try {
|
||||
const identifier = ESX.GetPlayerFromId(getSource()).getIdentifier();
|
||||
await deleteTweet(identifier, tweetId);
|
||||
|
||||
emitNet(events.TWITTER_DELETE_TWEET_SUCCESS, getSource());
|
||||
} catch (e) {
|
||||
emitNet(events.TWITTER_DELETE_TWEET_FAILURE, getSource());
|
||||
}
|
||||
});
|
||||
|
||||
onNet(events.TWITTER_TOGGLE_LIKE, async (tweetId: number) => {
|
||||
try {
|
||||
const identifier = ESX.GetPlayerFromId(getSource()).getIdentifier();
|
||||
|
||||
@@ -17,6 +17,9 @@ export default {
|
||||
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",
|
||||
|
||||
Reference in new issue
Block a user