diff --git a/fxmanifest.lua b/fxmanifest.lua
index 6d23a81..8cf45c4 100644
--- a/fxmanifest.lua
+++ b/fxmanifest.lua
@@ -27,5 +27,6 @@ files {
'resources/html/*.js',
'resources/html/media/frames/*.png',
'resources/html/media/backgrounds/*.png',
- 'resources/html/media/backgrounds/*.jpg'
+ 'resources/html/media/backgrounds/*.jpg',
+ 'resources/html/media/twitter/*'
}
\ No newline at end of file
diff --git a/phone/package.json b/phone/package.json
index 0c5d0ed..c562e69 100644
--- a/phone/package.json
+++ b/phone/package.json
@@ -6,10 +6,12 @@
"@babel/polyfill": "^7.4.4",
"@material-ui/core": "^4.11.0",
"@material-ui/icons": "^4.9.1",
+ "@material-ui/lab": "^4.0.0-alpha.56",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
"core-js": "^3.6.5",
+ "emoji-mart": "^3.0.0",
"husky": "^4.2.5",
"i18next": "^19.7.0",
"prettier": "^2.0.5",
@@ -20,7 +22,8 @@
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.3",
"recoil": "^0.0.10",
- "styled-components": "^5.1.1"
+ "styled-components": "^5.1.1",
+ "uuid": "^8.3.0"
},
"devDependencies": {
"@babel/cli": "^7.4.4",
diff --git a/phone/src/Phone.js b/phone/src/Phone.js
index 7abe17a..c84c01d 100644
--- a/phone/src/Phone.js
+++ b/phone/src/Phone.js
@@ -17,6 +17,7 @@ import { usePhoneService } from "./os/phone/hooks/usePhoneService";
import { useApps } from "./os/apps/hooks/useApps";
import { useContactsService } from "./apps/contacts/hooks/useContactsService";
+import { useTwitterService } from "./apps/twitter/hooks/useTwitterService";
//These events are just for testing. Comment it out before building.
setTimeout(() => {
@@ -73,6 +74,7 @@ function Phone() {
const { allApps } = useApps();
useSimcardService();
useContactsService();
+ useTwitterService();
useInitKeyboard();
if (visibility === false) {
diff --git a/phone/src/apps/twitter/components/AddTweetModal.js b/phone/src/apps/twitter/components/AddTweetModal.js
new file mode 100644
index 0000000..c6d6ea4
--- /dev/null
+++ b/phone/src/apps/twitter/components/AddTweetModal.js
@@ -0,0 +1,188 @@
+import React, { useState, useEffect } from "react";
+import { makeStyles } from "@material-ui/core/styles";
+import { Button } from "@material-ui/core";
+import CloseIcon from "@material-ui/icons/Close";
+import { v4 as uuidv4 } from "uuid";
+
+import Nui from "../../../os/nui-events/utils/Nui";
+import Modal from "../../../ui/components/Modal";
+import { IMAGE_DELIMITER } from "../utils/images";
+import { withValidImage } from "../utils/images";
+import { useModal } from "../hooks/useModal";
+import EmojiSelect from "./EmojiSelect";
+import ImageDisplay from "./images/ImageDisplay";
+import ImagePrompt from "./images/ImagePrompt";
+import TweetMessage from "./tweet/TweetMessage";
+import ControlButtons from "./buttons/ControlButtons";
+import IconButtons from "./buttons/IconButtons";
+import { usePhone } from "../../../os/phone/hooks/usePhone";
+
+const useStyles = makeStyles((theme) => ({
+ root: {
+ zIndex: 10,
+ background: "#424242",
+ marginTop: "15px",
+ width: "90%",
+ display: "flex",
+ flexFlow: "column nowrap",
+ position: "absolute",
+ top: "80px",
+ },
+ button: {
+ margin: 5,
+ marginTop: 20,
+ },
+ close: {
+ position: "absolute",
+ top: "12px",
+ right: "4px",
+ zIndex: 2,
+ },
+ buttonsContainer: {
+ paddingBottom: "8px",
+ display: "flex",
+ flexFlow: "row nowrap",
+ justifyContent: "space-between",
+ flex: "1 0 45px",
+ },
+ emojiPicker: {
+ background: "none",
+ border: "none",
+ boxShadow: "none",
+ },
+}));
+
+export const AddTweetModal = () => {
+ const classes = useStyles();
+ const { message, setMessage, modalVisible, setModalVisible } = useModal();
+ const { config } = usePhone();
+
+ const [showEmoji, setShowEmoji] = useState(false);
+ const [showImagePrompt, setShowImagePrompt] = useState(false);
+ const [link, setLink] = useState("");
+
+ const [images, setImages] = useState([]);
+
+ const reset = () => {
+ setShowImagePrompt(null);
+ setShowEmoji(false);
+
+ setLink("");
+ setImages([]);
+ setMessage("");
+ };
+
+ const _handleClose = () => {
+ reset();
+ setModalVisible(false);
+ };
+
+ // when the user presses escape we should close the modal
+ const _handleEscape = (e) => {
+ const isEscapeKey = e.key == "Escape" || e.key == "Esc";
+ if (isEscapeKey) {
+ e.preventDefault();
+ _handleClose();
+ }
+ };
+ useEffect(() => {
+ const listener = window.addEventListener("keydown", _handleEscape, true);
+ return () => window.removeEventListener("keydown", listener);
+ }, []);
+
+ const submitTweet = () => {
+ const cleanedMessage = message.trim();
+ if (cleanedMessage.length === 0) return;
+ if (cleanedMessage.length > config.twitter.characterLimit) return;
+
+ const data = {
+ message,
+ images:
+ images && images.length > 0
+ ? images.map((image) => image.link).join(IMAGE_DELIMITER)
+ : "",
+ realUser: "testUser",
+ };
+ Nui.send("phone:createTweet", data);
+ _handleClose();
+ };
+
+ const handleMessageChange = (e) => setMessage(e.target.value);
+
+ const addImage = () => {
+ // strip any whitespace from the link in case the user
+ // added some spaces/returns accidentally
+ const cleanedLink = link.replace("/ /g", "");
+ // because we're only storing strings in the database we need
+ // to give this an arbirtrary (but unique) id so that we can
+ // correctly filter an array of images when the user wants to
+ // delete them. This handles an edge case where the user adds
+ // two of the same image.
+ const image = { id: uuidv4(), link: cleanedLink };
+ // it's worth noting that we only perform this validation on
+ // the client of the user who is submitting the image. When
+ // other users see this image on their TweetList it will be
+ // from the database and should already have passed through
+ // this logic
+ withValidImage(cleanedLink, () => setImages([...images, image]));
+
+ setShowImagePrompt(false);
+ setLink('')
+ };
+ const removeImage = (id) =>
+ setImages(images.filter((image) => id !== image.id));
+ const handleimageChange = (e) => setLink(e.target.value);
+
+ const toggleShowImagePrompt = () => {
+ setShowEmoji(false); // clear the emoji so we can switch between emoji/images
+ setShowImagePrompt(!showImagePrompt);
+ };
+ const toggleShowEmoji = () => {
+ // clear the images so we can seemlessly toggle between emoji/images
+ setShowImagePrompt(false);
+ setImages("");
+ setShowEmoji(!showEmoji);
+ };
+
+ // this is when a user clicks on an emoji icon itself (i.e. a smiley face)
+ // not the emoji icon on the UI
+ const handleSelectEmoji = (emojiObject, e) => {
+ setMessage(message.concat(emojiObject.native));
+ };
+
+ if (!config) return null;
+
+ return (
+
+
+
+
+
+ 0}
+ images={images}
+ removeImage={removeImage}
+ />
+
+
+
+
+
+ );
+};
+
+export default AddTweetModal;
diff --git a/phone/src/apps/twitter/components/Avatar.js b/phone/src/apps/twitter/components/Avatar.js
new file mode 100644
index 0000000..35f4d83
--- /dev/null
+++ b/phone/src/apps/twitter/components/Avatar.js
@@ -0,0 +1,56 @@
+import React, { useState } from "react";
+import { makeStyles } from "@material-ui/core/styles";
+
+import { usePhone } from "../../../os/phone/hooks/usePhone";
+import { IMG_DEFAULT_AVATAR, IMG_INVALID_AVATAR } from "../utils/constants";
+
+const useStyles = makeStyles({
+ root: {
+ width: "100%",
+ },
+ img: {
+ borderRadius: "50%",
+ objectFit: "cover",
+ },
+});
+
+function Avatar({ avatarUrl, showInvalidImage, height, width }) {
+ const classes = useStyles();
+ const [showImageError, setShowImageError] = useState(false);
+ const { config } = usePhone();
+
+ const handleImageError = () => setShowImageError(true);
+ const handleImageLoad = () => setShowImageError(false);
+
+ if (!config || !config.twitter.enableAvatars) return null;
+
+ return (
+
+ {showImageError && (
+

+ )}
+

+
+ );
+}
+
+Avatar.defaultProps = {
+ avatarUrl: null,
+ showInvalidImage: false,
+ height: "125px",
+ width: "125px",
+};
+
+export default Avatar;
diff --git a/phone/src/apps/twitter/components/BottomNavigation.js b/phone/src/apps/twitter/components/BottomNavigation.js
new file mode 100644
index 0000000..91cd2b8
--- /dev/null
+++ b/phone/src/apps/twitter/components/BottomNavigation.js
@@ -0,0 +1,43 @@
+import React from "react";
+import { Link } from "react-router-dom";
+import { makeStyles } from "@material-ui/core/styles";
+import { BottomNavigation, BottomNavigationAction } from "@material-ui/core";
+import HomeIcon from "@material-ui/icons/Home";
+import SearchIcon from "@material-ui/icons/Search";
+import ProfileIcon from "@material-ui/icons/Person";
+
+const useStyles = makeStyles({
+ root: {
+ width: "100%",
+ },
+});
+
+export function TwitterBottomNavigation({ activePage, handleChange }) {
+ const classes = useStyles();
+
+ return (
+
+ }
+ />
+ }
+ />
+ }
+ />
+
+ );
+}
+
+export default TwitterBottomNavigation;
diff --git a/phone/src/apps/twitter/components/EmojiSelect.js b/phone/src/apps/twitter/components/EmojiSelect.js
new file mode 100644
index 0000000..fe4fa6d
--- /dev/null
+++ b/phone/src/apps/twitter/components/EmojiSelect.js
@@ -0,0 +1,17 @@
+import React, { memo } from "react";
+import { Picker } from "emoji-mart";
+
+export const EmojiSelect = ({ visible, onEmojiClick }) => {
+ if (!visible) return null;
+
+ return (
+
+ );
+};
+
+export default memo(EmojiSelect); // The picker is an expensive render
diff --git a/phone/src/apps/twitter/components/TwitterApp.js b/phone/src/apps/twitter/components/TwitterApp.js
new file mode 100644
index 0000000..7cb545f
--- /dev/null
+++ b/phone/src/apps/twitter/components/TwitterApp.js
@@ -0,0 +1,96 @@
+import React, { useState, useEffect } from "react";
+import { Switch, Route } from "react-router-dom";
+import { makeStyles } from "@material-ui/core/styles";
+
+import Nui from "../../../os/nui-events/utils/Nui";
+import { AppWrapper } from "../../../ui/components";
+import { AppContent } from "../../../ui/components/AppContent";
+import TweetListContainer from "./tweet/TweetListContainer";
+import AddTweetModal from "./AddTweetModal";
+import { useModal } from "../hooks/useModal";
+import TweetButton from "./buttons/TweetButton";
+import TwitterTitle from "./TwitterTitle";
+import BottomNavigation from "./BottomNavigation";
+import TwitterProfile from "./profile/Profile";
+import AlertBar from "./alerts/AlertBar";
+import TwitterSearch from "./TwitterSearch";
+
+import "./twitter.css";
+import "emoji-mart/css/emoji-mart.css";
+import { useProfile } from "../hooks/useProfile";
+import ProfilePrompt from "./profile/ProfilePrompt";
+
+const useStyles = makeStyles(() => ({
+ backgroundModal: {
+ background: "black",
+ opacity: "0.6",
+ position: "absolute",
+ top: 0,
+ left: 0,
+ right: 0,
+ bottom: 0,
+ zIndex: 5,
+ },
+}));
+
+const TWEETS_REFRESH_RATE = 15000; // TODO move this to twitter config
+
+export const TwitterApp = () => {
+ const classes = useStyles();
+ const { modalVisible, setModalVisible } = useModal();
+ const [activePage, setActivePage] = useState(0);
+ const { profile } = useProfile();
+
+ useEffect(() => {
+ Nui.send("phone:getOrCreateTwitterProfile", {});
+ Nui.send("phone:fetchTweets", {});
+
+ // this is a polling implementation. It is possible that
+ // there is some interaction where, on a new tweet, all
+ // clients are sent the updated query data. Until that can
+ // be accomplished this is naive but robust.
+ //
+ // TODO don't call fetchTweets - implement a function that only
+ // returns tweets that we don't already have
+ const timeout = window.setTimeout(() => {
+ Nui.send("phone:fetchTweets", {});
+ }, TWEETS_REFRESH_RATE);
+ return () => window.clearTimeout(timeout);
+ }, []);
+
+ // before any other action can be taken by the user we force
+ // them have a profile name
+ const promptProfileName =
+ profile && (!profile.profile_name || !profile.profile_name.trim());
+
+ const openModal = () => setModalVisible(true);
+ const handlePageChange = (e, page) => setActivePage(page);
+ const showTweetButton = !promptProfileName && activePage === 0;
+
+ return (
+
+ );
+};
diff --git a/phone/src/apps/twitter/components/TwitterSearch.js b/phone/src/apps/twitter/components/TwitterSearch.js
new file mode 100644
index 0000000..8e033bf
--- /dev/null
+++ b/phone/src/apps/twitter/components/TwitterSearch.js
@@ -0,0 +1,59 @@
+import React, { useState } from "react";
+import { useTranslation } from "react-i18next";
+import { makeStyles } from "@material-ui/core/styles";
+import { TextField } from "@material-ui/core";
+import TweetList from "./tweet/TweetList";
+
+import Nui from "../../../os/nui-events/utils/Nui";
+import SearchButton from "./buttons/SearchButton";
+import { useFilteredTweets } from "../hooks/useFilteredTweets";
+
+const useStyles = makeStyles({
+ root: {
+ width: "100%",
+ },
+ searchContainer: {
+ padding: "15px",
+ },
+ search: {
+ width: "100%",
+ },
+});
+
+function TwitterSearch() {
+ const classes = useStyles();
+ const { t } = useTranslation();
+ const [searchValue, setSearchValue] = useState("");
+ const { tweets, setTweets } = useFilteredTweets();
+
+ const handleChange = (e) => setSearchValue(e.target.value);
+
+ const handleSubmit = () => {
+ const cleanedSearchValue = searchValue.trim();
+ if (!cleanedSearchValue) return;
+
+ Nui.send("phone:fetchTweetsFiltered", cleanedSearchValue);
+ };
+
+ return (
+ <>
+
+
+ input && input.focus()}
+ />
+
+ {tweets && tweets.length > 0 &&
}
+
+
+ >
+ );
+}
+
+export default TwitterSearch;
diff --git a/phone/src/apps/twitter/components/TwitterTitle.js b/phone/src/apps/twitter/components/TwitterTitle.js
new file mode 100644
index 0000000..1182c4e
--- /dev/null
+++ b/phone/src/apps/twitter/components/TwitterTitle.js
@@ -0,0 +1,31 @@
+import React from "react";
+import Paper from "@material-ui/core/Paper";
+import { makeStyles } from "@material-ui/core";
+import TwitterIcon from "@material-ui/icons/Twitter";
+
+const useStyles = makeStyles((theme) => ({
+ root: {
+ height: "60px",
+ width: "100%",
+ display: "flex",
+ flexFlow: "row nowrap",
+ justifyContent: "center",
+ alignItems: "center",
+ background: "#424242",
+ },
+ icon: {
+ color: "#00acee",
+ fontSize: 30,
+ },
+}));
+
+export function TwitterTitle() {
+ const classes = useStyles();
+ return (
+
+
+
+ );
+}
+
+export default TwitterTitle;
diff --git a/phone/src/apps/twitter/components/alerts/Alert.js b/phone/src/apps/twitter/components/alerts/Alert.js
new file mode 100644
index 0000000..2ba1e67
--- /dev/null
+++ b/phone/src/apps/twitter/components/alerts/Alert.js
@@ -0,0 +1,8 @@
+import React from "react";
+import MuiAlert from "@material-ui/lab/Alert";
+
+export function Alert(props) {
+ return ;
+}
+
+export default Alert;
diff --git a/phone/src/apps/twitter/components/alerts/AlertBar.js b/phone/src/apps/twitter/components/alerts/AlertBar.js
new file mode 100644
index 0000000..10dbce5
--- /dev/null
+++ b/phone/src/apps/twitter/components/alerts/AlertBar.js
@@ -0,0 +1,66 @@
+import React, { useEffect, useState } from "react";
+import { useTranslation } from "react-i18next";
+import { Snackbar } from "@material-ui/core";
+import { makeStyles } from "@material-ui/core/styles";
+
+import { useProfile } from "../../hooks/useProfile";
+import { useTweetStatus } from "../../hooks/useTweetStatus";
+import Alert from "./Alert";
+
+const useStyles = makeStyles((theme) => ({
+ root: {
+ width: "100%",
+ bottom: "60px",
+ },
+}));
+
+const ALERT_TIMEOUT = 4000;
+
+export default function AlertBar() {
+ const classes = useStyles();
+ const { t } = useTranslation();
+ const { updateProfileSuccessful, setUpdateProfileSuccessful } = useProfile();
+ const { createTweetSuccessful, setCreateTweetSuccessful } = useTweetStatus();
+ const [severity, setSeverity] = useState(null);
+ const [open, setOpen] = useState(null);
+ const [message, setMessage] = useState(null);
+
+ const handleClose = () => {
+ setOpen(false);
+ setUpdateProfileSuccessful(null);
+ setCreateTweetSuccessful(null);
+ };
+
+ useEffect(() => {
+ if (createTweetSuccessful === true) {
+ setOpen(true);
+ setSeverity("success");
+ setMessage(t("APPS_TWITTER_CREATE_SUCCESS"));
+ } else if (createTweetSuccessful === false) {
+ setOpen(true);
+ setSeverity("error");
+ setMessage(t("APPS_TWITTER_CREATE_FAILED"));
+ } else if (updateProfileSuccessful === true) {
+ setOpen(true);
+ setSeverity("success");
+ setMessage(t("APPS_TWITTER_EDIT_PROFILE_SUCCESS"));
+ } else if (updateProfileSuccessful === false) {
+ setOpen(true);
+ setSeverity("error");
+ setMessage(t("APPS_TWITTER_EDIT_PROFILE_FAILURE"));
+ }
+ }, [updateProfileSuccessful, createTweetSuccessful]);
+
+ return (
+
+
+ {message}
+
+
+ );
+}
diff --git a/phone/src/apps/twitter/components/buttons/ControlButtons.js b/phone/src/apps/twitter/components/buttons/ControlButtons.js
new file mode 100644
index 0000000..5841c35
--- /dev/null
+++ b/phone/src/apps/twitter/components/buttons/ControlButtons.js
@@ -0,0 +1,53 @@
+import React from "react";
+import { useTranslation } from "react-i18next";
+import { makeStyles } from "@material-ui/core/styles";
+import { Button } from "@material-ui/core";
+
+const useStyles = makeStyles((theme) => ({
+ buttons: {
+ display: "flex",
+ flexFlow: "row nowrap",
+ justifyContent: "flex-end",
+ alignItems: "justify-content",
+ marginRight: "15px",
+ },
+ close: {
+ marginLeft: "8px",
+ },
+}));
+
+export const ControlButtons = ({
+ showImagePrompt,
+ showEmoji,
+ onCloseClick,
+ onPrimaryClick,
+}) => {
+ const classes = useStyles();
+ const { t } = useTranslation();
+
+ const imagePromptVisible = showImagePrompt && !showEmoji;
+ const primaryButtonText = imagePromptVisible
+ ? t("APPS_TWITTER_SUBMIT_IMAGE")
+ : t("APPS_TWITTER_TWEET");
+ const showCloseButton = showImagePrompt || showEmoji;
+
+ return (
+
+
+ {showCloseButton && (
+
+ )}
+
+ );
+};
+
+export default ControlButtons;
diff --git a/phone/src/apps/twitter/components/buttons/IconButtons.js b/phone/src/apps/twitter/components/buttons/IconButtons.js
new file mode 100644
index 0000000..18053ca
--- /dev/null
+++ b/phone/src/apps/twitter/components/buttons/IconButtons.js
@@ -0,0 +1,40 @@
+import React from "react";
+import { makeStyles } from "@material-ui/core/styles";
+import { Button } from "@material-ui/core";
+import InsertPhotoIcon from "@material-ui/icons/InsertPhoto";
+import EmojiIcon from "@material-ui/icons/SentimentSatisfied";
+import { usePhone } from "../../../../os/phone/hooks/usePhone";
+
+const useStyles = makeStyles((theme) => ({
+ buttons: {
+ display: "flex",
+ flexFlow: "row nowrap",
+ justifyContent: "flex-start",
+ paddingLeft: "5px", // re-align left buttons after overriding material-ui spacing
+ },
+ button: {
+ background: "transparent",
+ minWidth: "45px", // override default material-ui spacing between buttons
+ },
+}));
+
+export const IconButtons = ({ onImageClick, onEmojiClick }) => {
+ const classes = useStyles();
+ const { config } = usePhone();
+
+ if (!config) return null;
+ const { enableImages, enableEmojis } = config.twitter;
+
+ return (
+
+ {enableImages && ()}
+ {enableEmojis && ()}
+
+ );
+};
+
+export default IconButtons;
diff --git a/phone/src/apps/twitter/components/buttons/ProfileUpdateButton.js b/phone/src/apps/twitter/components/buttons/ProfileUpdateButton.js
new file mode 100644
index 0000000..efc5347
--- /dev/null
+++ b/phone/src/apps/twitter/components/buttons/ProfileUpdateButton.js
@@ -0,0 +1,50 @@
+import React, { useState, useEffect } from "react";
+import { makeStyles } from "@material-ui/core/styles";
+import { Fab } from "@material-ui/core";
+import PublishIcon from "@material-ui/icons/Publish";
+
+import { useProfile } from "../../hooks/useProfile";
+
+const useStyles = makeStyles((theme) => ({
+ root: {
+ position: "absolute",
+ bottom: "15px",
+ right: "15px",
+ },
+ button: {
+ background: "#00acee",
+ },
+}));
+
+const MINIMUM_LOAD_TIME = 750;
+
+export function ProfileUpdateButton({ handleClick }) {
+ const classes = useStyles();
+ const [minimumLoadPassed, setMimimumLoadPassed] = useState(true);
+ const { updateProfileLoading } = useProfile();
+
+ useEffect(() => {
+ setMimimumLoadPassed(false);
+ const timeout = window.setTimeout(() => {
+ setMimimumLoadPassed(true);
+ }, MINIMUM_LOAD_TIME);
+ return () => window.clearTimeout(timeout);
+ }, [updateProfileLoading]);
+
+ const isLoading = updateProfileLoading || !minimumLoadPassed;
+
+ return (
+
+ );
+}
+
+export default ProfileUpdateButton;
diff --git a/phone/src/apps/twitter/components/buttons/QuoteButton.js b/phone/src/apps/twitter/components/buttons/QuoteButton.js
new file mode 100644
index 0000000..a1008ce
--- /dev/null
+++ b/phone/src/apps/twitter/components/buttons/QuoteButton.js
@@ -0,0 +1,26 @@
+import React from "react";
+import { useSetRecoilState } from "recoil";
+import { Button } from "@material-ui/core";
+import QuoteIcon from "@material-ui/icons/FormatQuote";
+
+import { twitterState } from "../../hooks/state";
+
+export const QuoteButton = ({ message }) => {
+ const setModalVisible = useSetRecoilState(twitterState.showCreateTweetModal);
+ const setMessage = useSetRecoilState(twitterState.modalMessage);
+
+ const handleClick = () => {
+ setMessage(`> ${message}
+
+`);
+ setModalVisible(true);
+ };
+
+ return (
+
+ );
+};
+
+export default QuoteButton;
diff --git a/phone/src/apps/twitter/components/buttons/ReplyButton.js b/phone/src/apps/twitter/components/buttons/ReplyButton.js
new file mode 100644
index 0000000..ee1fd13
--- /dev/null
+++ b/phone/src/apps/twitter/components/buttons/ReplyButton.js
@@ -0,0 +1,24 @@
+import React from "react";
+import { useSetRecoilState } from "recoil";
+import { Button } from "@material-ui/core";
+import ReplyIcon from "@material-ui/icons/Reply";
+
+import { twitterState } from "../../hooks/state";
+
+export const ReplyButton = ({ profile_name }) => {
+ const setModalVisible = useSetRecoilState(twitterState.showCreateTweetModal);
+ const setMessage = useSetRecoilState(twitterState.modalMessage);
+
+ const handleClick = () => {
+ setMessage(`@${profile_name} `);
+ setModalVisible(true);
+ };
+
+ return (
+
+ );
+};
+
+export default ReplyButton;
diff --git a/phone/src/apps/twitter/components/buttons/SearchButton.js b/phone/src/apps/twitter/components/buttons/SearchButton.js
new file mode 100644
index 0000000..c01456a
--- /dev/null
+++ b/phone/src/apps/twitter/components/buttons/SearchButton.js
@@ -0,0 +1,29 @@
+import React from "react";
+import { makeStyles } from "@material-ui/core/styles";
+import { Fab } from "@material-ui/core";
+import SearchIcon from "@material-ui/icons/Search";
+
+const useStyles = makeStyles((theme) => ({
+ root: {
+ position: "absolute",
+ bottom: "15px",
+ right: "15px",
+ },
+ button: {
+ background: "#00acee",
+ },
+}));
+
+export function ProfileUpdateButton({ handleClick }) {
+ const classes = useStyles();
+
+ return (
+
+
+
+
+
+ );
+}
+
+export default ProfileUpdateButton;
diff --git a/phone/src/apps/twitter/components/buttons/TweetButton.js b/phone/src/apps/twitter/components/buttons/TweetButton.js
new file mode 100644
index 0000000..3c96214
--- /dev/null
+++ b/phone/src/apps/twitter/components/buttons/TweetButton.js
@@ -0,0 +1,29 @@
+import React from "react";
+import { makeStyles } from "@material-ui/core/styles";
+import { Fab } from "@material-ui/core";
+import CreateIcon from "@material-ui/icons/Create";
+
+const useStyles = makeStyles(() => ({
+ root: {
+ position: "absolute",
+ bottom: "75px",
+ right: "15px",
+ },
+ button: {
+ background: "#00acee",
+ },
+}));
+
+export function TweetButton({ openModal }) {
+ const classes = useStyles();
+
+ return (
+
+
+
+
+
+ );
+}
+
+export default TweetButton;
diff --git a/phone/src/apps/twitter/components/images/Image.js b/phone/src/apps/twitter/components/images/Image.js
new file mode 100644
index 0000000..2e5c860
--- /dev/null
+++ b/phone/src/apps/twitter/components/images/Image.js
@@ -0,0 +1,57 @@
+import React from "react";
+import { IconButton } from "@material-ui/core";
+import { makeStyles } from "@material-ui/core/styles";
+import CloseIcon from "@material-ui/icons/Close";
+
+const useStyles = makeStyles(() => ({
+ root: {
+ margin: "2px 15px",
+ },
+ imageContainer: {
+ // catch the close button here so it doesn't go all the way up to the modal
+ position: "relative",
+ display: "inline-block",
+ },
+ imgButton: {
+ position: "absolute", // show the close button in the top right of the image
+ top: "2px",
+ right: "5px",
+ backgroundColor: "#000",
+ opacity: 0.7,
+ "&:hover": {
+ // fixes a bug where when the user closes one image material-ui puts
+ // the hover status on the previous image
+ backgroundColor: "#000",
+ },
+ },
+ img: {
+ maxHeight: "125px", // constrain images so we don't overwhelm the UI
+ maxWidth: "300px",
+ padding: "0px 3px 3px 0px",
+ },
+ imgSmall: {
+ maxHeight: "200px", // constrain images so we don't overwhelm the UI
+ maxWidth: "100%",
+ padding: "0px 1px 1px 0px",
+ },
+}));
+
+export const Image = ({ link, handleClick, small }) => {
+ const classes = useStyles();
+ return (
+
+ {handleClick && (
+
+
+
+ )}
+

+
+ );
+};
+
+export default Image;
diff --git a/phone/src/apps/twitter/components/images/ImageDisplay.js b/phone/src/apps/twitter/components/images/ImageDisplay.js
new file mode 100644
index 0000000..5ed6ceb
--- /dev/null
+++ b/phone/src/apps/twitter/components/images/ImageDisplay.js
@@ -0,0 +1,29 @@
+import React from "react";
+
+import Image from "./Image";
+
+export const ImageDisplay = ({ visible, images, removeImage, small }) => {
+ if (!visible || !images || images.length === 0) return null;
+
+ const styles = { margin: small ? "2px 0px" : "2px 15px" };
+
+ return (
+
+ {images.map((image) => (
+ removeImage(image.id) : null}
+ small={small}
+ />
+ ))}
+
+ );
+};
+
+ImageDisplay.defaultProps = {
+ removeImage: null,
+ small: false,
+};
+
+export default ImageDisplay;
diff --git a/phone/src/apps/twitter/components/images/ImagePrompt.js b/phone/src/apps/twitter/components/images/ImagePrompt.js
new file mode 100644
index 0000000..ae1d7c0
--- /dev/null
+++ b/phone/src/apps/twitter/components/images/ImagePrompt.js
@@ -0,0 +1,36 @@
+import React from "react";
+import { useTranslation } from "react-i18next";
+import { makeStyles } from "@material-ui/core/styles";
+import { TextField } from "@material-ui/core";
+
+const useStyles = makeStyles((theme) => ({
+ textField: {
+ flex: "1 1 100%",
+ padding: "10px 15px",
+ marginTop: "15px",
+ },
+ textFieldInput: {
+ fontSize: "22px",
+ },
+}));
+
+export const ImagePrompt = ({ visible, value, handleChange }) => {
+ const { t } = useTranslation();
+ const classes = useStyles();
+
+ if (!visible) return null;
+ return (
+ input && input.focus()}
+ />
+ );
+};
+
+export default ImagePrompt;
diff --git a/phone/src/apps/twitter/components/profile/Profile.js b/phone/src/apps/twitter/components/profile/Profile.js
new file mode 100644
index 0000000..f14690c
--- /dev/null
+++ b/phone/src/apps/twitter/components/profile/Profile.js
@@ -0,0 +1,95 @@
+import React, { useState } from "react";
+import { makeStyles } from "@material-ui/core/styles";
+import { useTranslation } from "react-i18next";
+
+import Nui from "../../../../os/nui-events/utils/Nui";
+import { useProfile } from "../../hooks/useProfile";
+import Avatar from "../Avatar";
+import ProfileField from "./ProfileField";
+import ProfileUpdateButton from "../buttons/ProfileUpdateButton";
+import { usePhone } from "../../../../os/phone/hooks/usePhone";
+
+const useStyles = makeStyles((theme) => ({
+ root: {
+ position: "relative",
+ width: "100%",
+ height: "100%",
+ padding: "15px",
+ },
+ spacer: {
+ height: "8px",
+ },
+}));
+
+export function Profile() {
+ const classes = useStyles();
+ const { t } = useTranslation();
+ const { profile } = useProfile();
+ const { config } = usePhone();
+
+
+ // note that this assumes we are defensively checking
+ // that profile is not null in a parent above this component.
+ // Annoyingling adding conditionals above this line to not render
+ // when profile === null results in a react error that different
+ // amounts of hooks are rendering
+ const [avatarUrl, handleAvatarChange] = useState(profile.avatar_url);
+ const [name, handleNameChange] = useState(profile.profile_name || "");
+ const [bio, handleBioChange] = useState(profile.bio || "");
+ const [location, handleLocationChange] = useState(profile.location || "");
+ const [job, handleJobChange] = useState(profile.job || "");
+
+ const handleUpdate = () => {
+ const data = {
+ avatar_url: avatarUrl,
+ profile_name: name,
+ bio,
+ location,
+ job,
+ };
+ Nui.send("phone:updateTwitterProfile", data);
+ };
+
+ // fetching the config is an asynchronous call so defend against it
+ if (!config) return null;
+
+ const { enableAvatars, allowEdtiableProfileName } = config.twitter;
+
+ return (
+
+ {enableAvatars &&
}
+
+
+
+
+
+
+
+
+ );
+}
+
+export default Profile;
diff --git a/phone/src/apps/twitter/components/profile/ProfileField.js b/phone/src/apps/twitter/components/profile/ProfileField.js
new file mode 100644
index 0000000..da7150c
--- /dev/null
+++ b/phone/src/apps/twitter/components/profile/ProfileField.js
@@ -0,0 +1,47 @@
+import React from "react";
+import { makeStyles } from "@material-ui/core/styles";
+import { TextField } from "@material-ui/core";
+
+const useStyles = makeStyles({
+ formContainer: {
+ width: "100%",
+ marginTop: "8px",
+ },
+ textField: {
+ width: "100%",
+ },
+});
+
+function ProfileField({
+ label,
+ value,
+ handleChange,
+ allowChange,
+ multiline,
+ inputRef,
+}) {
+ const classes = useStyles();
+ const _handleChange = (e) => handleChange(e.target.value);
+
+ return (
+
+
+
+ );
+}
+
+ProfileField.defaultProps = {
+ allowChange: true,
+ multiline: false,
+ inputRef: null,
+};
+
+export default ProfileField;
diff --git a/phone/src/apps/twitter/components/profile/ProfilePrompt.js b/phone/src/apps/twitter/components/profile/ProfilePrompt.js
new file mode 100644
index 0000000..307aecb
--- /dev/null
+++ b/phone/src/apps/twitter/components/profile/ProfilePrompt.js
@@ -0,0 +1,49 @@
+import React, { useState } from "react";
+import { makeStyles } from "@material-ui/core/styles";
+import { useTranslation } from "react-i18next";
+
+import Nui from "../../../../os/nui-events/utils/Nui";
+import { useProfile } from "../../hooks/useProfile";
+import ProfileField from "./ProfileField";
+import ProfileUpdateButton from "../buttons/ProfileUpdateButton";
+
+const useStyles = makeStyles((theme) => ({
+ root: {
+ position: "relative",
+ width: "100%",
+ height: "100%",
+ padding: "15px",
+ },
+ spacer: {
+ height: "8px",
+ },
+}));
+
+export function ProfilePrompt() {
+ const classes = useStyles();
+ const { t } = useTranslation();
+ const { profile } = useProfile();
+ const [name, handleNameChange] = useState(profile.profile_name || "");
+
+ const handleUpdate = () => {
+ const data = {
+ ...profile,
+ profile_name: name,
+ };
+ Nui.send("phone:updateTwitterProfile", data);
+ };
+
+ return (
+
+ );
+}
+
+export default ProfilePrompt;
diff --git a/phone/src/apps/twitter/components/tweet/Tweet.js b/phone/src/apps/twitter/components/tweet/Tweet.js
new file mode 100644
index 0000000..5f87c9b
--- /dev/null
+++ b/phone/src/apps/twitter/components/tweet/Tweet.js
@@ -0,0 +1,126 @@
+import React from "react";
+import { useTranslation } from "react-i18next";
+import { makeStyles } from "@material-ui/core/styles";
+import {
+ ListItemAvatar,
+ Avatar as MuiAvatar,
+ Button,
+ Typography,
+} from "@material-ui/core";
+import FavoriteBorderIcon from "@material-ui/icons/FavoriteBorder";
+import MoreIcon from "@material-ui/icons/MoreVert";
+
+import { ListItem } from "../../../../ui/components/ListItem";
+import { secondsToHumanReadable } from "../../utils/time";
+import ReplyButton from "../buttons/ReplyButton";
+import ImageDisplay from "../images/ImageDisplay";
+import Avatar from "../Avatar";
+import { QuoteButton } from "../buttons/QuoteButton";
+import { usePhone } from "../../../../os/phone/hooks/usePhone";
+
+const useStyles = makeStyles(() => ({
+ root: {
+ overflowX: "hidden",
+ display: "flex",
+ flexFlow: "row nowrap",
+ alignItems: "flex-start",
+ width: "100%",
+ marginTop: "3px",
+ },
+ content: {
+ display: "flex",
+ marginTop: "-10px", // easier to do this here than override the MUI styles
+ flexFlow: "column nowrap",
+ width: "100%",
+ },
+ primary: {
+ display: "flex",
+ flexFlow: "row nowrap",
+ width: "100%",
+ alignItems: "flex-end",
+ },
+ profile: {
+ fontSize: "18px",
+ fontWeight: "bold",
+ },
+ date: {
+ marginLeft: "10px",
+ fontSize: "14px",
+ },
+ message: {
+ fontSize: "18px",
+ color: "rgba(255, 255, 255, 0.7)",
+ },
+ buttonContainer: {
+ display: "flex",
+ flexFlow: "row nowrap",
+ justifyContent: "space-between",
+ width: "100%",
+ marginLeft: "-20px", // easier to do this here than override the MUI styles
+ marginTop: "3px",
+ },
+}));
+
+export const Tweet = (tweet) => {
+ const {
+ message,
+ images,
+ avatar_url,
+ profile_name,
+ seconds_since_tweet,
+ } = tweet;
+ const classes = useStyles();
+ const { t } = useTranslation();
+ const { config } = usePhone();
+
+ if (!config) return null;
+ const { enableAvatars, enableImages } = config.twitter;
+
+ // 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, "
");
+
+ const profileName = profile_name ? `@${profile_name}` : "";
+
+ return (
+
+ {enableAvatars && (
+
+
+
+
+
+ )}
+
+
+
{profileName}
+
+ {secondsToHumanReadable(t, seconds_since_tweet)}
+
+
+
+ {enableImages &&
}
+
+
+
+
+
+
+
+
+ );
+};
+
+export default Tweet;
diff --git a/phone/src/apps/twitter/components/tweet/TweetList.js b/phone/src/apps/twitter/components/tweet/TweetList.js
new file mode 100644
index 0000000..9b1e119
--- /dev/null
+++ b/phone/src/apps/twitter/components/tweet/TweetList.js
@@ -0,0 +1,34 @@
+import React, { useEffect, useState } from "react";
+
+import { List } from "../../../../ui/components/List";
+import Tweet from "./Tweet";
+import TweetSkeletonList from "./TweetSkeletonList";
+
+const MINIMUM_LOAD_TIME = 700;
+
+export function TweetList({ tweets }) {
+ const [minimumLoadPassed, setMimimumLoadPassed] = useState(false);
+
+ useEffect(() => {
+ const timeout = window.setTimeout(() => {
+ setMimimumLoadPassed(true);
+ }, MINIMUM_LOAD_TIME);
+ return () => window.clearTimeout(timeout);
+ });
+
+ // we add a minimum (but short) load time here so that
+ // there isn't a quick flash of loading and immediately
+ // another flash to the tweets screen.
+ const hasLoaded = tweets && minimumLoadPassed;
+
+ if (!hasLoaded) return ;
+ return (
+
+ {tweets.map((tweet) => (
+
+ ))}
+
+ );
+}
+
+export default TweetList;
diff --git a/phone/src/apps/twitter/components/tweet/TweetListContainer.js b/phone/src/apps/twitter/components/tweet/TweetListContainer.js
new file mode 100644
index 0000000..9c511b2
--- /dev/null
+++ b/phone/src/apps/twitter/components/tweet/TweetListContainer.js
@@ -0,0 +1,11 @@
+import React from "react";
+
+import { useTweets } from "../../hooks/useTweets";
+import TweetList from "./TweetList";
+
+export function TweetListContainer() {
+ const { tweets } = useTweets();
+ return ;
+}
+
+export default TweetListContainer;
diff --git a/phone/src/apps/twitter/components/tweet/TweetMessage.js b/phone/src/apps/twitter/components/tweet/TweetMessage.js
new file mode 100644
index 0000000..595ea4e
--- /dev/null
+++ b/phone/src/apps/twitter/components/tweet/TweetMessage.js
@@ -0,0 +1,44 @@
+import React, { useEffect, useRef } from "react";
+import { useTranslation } from "react-i18next";
+import { makeStyles } from "@material-ui/core/styles";
+import { TextField } from "@material-ui/core";
+import { usePhone } from "../../../../os/phone/hooks/usePhone";
+
+const useStyles = makeStyles((theme) => ({
+ textField: {
+ flex: "1 1 100%",
+ padding: "10px 15px",
+ marginTop: "15px",
+ },
+ textFieldInput: {
+ fontSize: "22px",
+ },
+ display: {
+ height: "200px",
+ },
+}));
+
+export const TweetMessage = ({ message, handleChange }) => {
+ const classes = useStyles();
+ const { config } = usePhone();
+ const { t } = useTranslation();
+
+ const overCharacterLimit = message.trim().length > config.twitter.characterLimit;
+ const characterWarningPrompt = `${t("APPS_TWITTER_TWEET_MESSAGE_CHAR_LIMIT")} (${config.twitter.characterLimit})`;
+
+ return (
+ input && input.focus()}
+ error={overCharacterLimit}
+ helperText={overCharacterLimit ? characterWarningPrompt : null}
+ />
+ );
+};
+
+export default TweetMessage;
diff --git a/phone/src/apps/twitter/components/tweet/TweetSkeleton.js b/phone/src/apps/twitter/components/tweet/TweetSkeleton.js
new file mode 100644
index 0000000..2154e88
--- /dev/null
+++ b/phone/src/apps/twitter/components/tweet/TweetSkeleton.js
@@ -0,0 +1,39 @@
+import React from "react";
+import Divider from "@material-ui/core/Divider";
+import { makeStyles } from "@material-ui/core/styles";
+import Skeleton from "@material-ui/lab/Skeleton";
+
+const useStyles = makeStyles({
+ root: {
+ width: "100%",
+ padding: "15px",
+ display: "flex",
+ flexFlow: "row nowrap",
+ marginTop: "3px",
+ marginBottom: "3px",
+ },
+ left: {},
+ right: {
+ marginLeft: "15px",
+ marginTop: "-5px",
+ },
+});
+
+export default function TweetSkeleton() {
+ const classes = useStyles();
+ return (
+ <>
+
+
+
+ >
+ );
+}
diff --git a/phone/src/apps/twitter/components/tweet/TweetSkeletonList.js b/phone/src/apps/twitter/components/tweet/TweetSkeletonList.js
new file mode 100644
index 0000000..b35be9e
--- /dev/null
+++ b/phone/src/apps/twitter/components/tweet/TweetSkeletonList.js
@@ -0,0 +1,23 @@
+import React from "react";
+
+import { List } from "../../../../ui/components/List";
+import TweetSkeleton from "./TweetSkeleton";
+
+export function TweetSkeletonList() {
+ return (
+
+
+
+
+
+
+
+
+
+
+
+
+ );
+}
+
+export default TweetSkeletonList;
diff --git a/phone/src/apps/twitter/components/twitter.css b/phone/src/apps/twitter/components/twitter.css
new file mode 100644
index 0000000..c543c1b
--- /dev/null
+++ b/phone/src/apps/twitter/components/twitter.css
@@ -0,0 +1,42 @@
+/* 00acee is "twitter blue" and we want to use that to override
+some of the Material UI primary theme settings */
+
+/* override buttons on the tweet modal */
+#twitter-app .MuiButton-containedPrimary {
+ background: #00acee !important;
+}
+
+/* override the bottom navigation active color */
+#twitter-app .Mui-selected {
+ color: #00acee !important;
+}
+/* override the FAB (action buttons) background when selected */
+#twitter-app .MuiFab-primary {
+ background: #00acee !important;
+}
+
+/* override the labels on text fields */
+#twitter-app .MuiInputLabel-formControl.Mui-focused {
+ color: #00acee !important;
+}
+
+/* override the underlines of text fields */
+#twitter-app .Mui-focused:after {
+ border-bottom-color: #00acee !important;
+}
+
+/*
+override position of the snackbar so that it appears
+within the phone rather than on the game UI */
+#twitter-app .MuiSnackbar-root {
+ position: absolute;
+}
+
+.emoji-mart {
+ margin: 0px 15px 8px 15px !important;
+ width: calc(100% - 30px) !important;
+}
+
+.emoji-mart-bar {
+ display: none;
+}
diff --git a/phone/src/apps/twitter/hooks/state.js b/phone/src/apps/twitter/hooks/state.js
new file mode 100644
index 0000000..130a509
--- /dev/null
+++ b/phone/src/apps/twitter/hooks/state.js
@@ -0,0 +1,40 @@
+import { atom } from "recoil";
+
+export const twitterState = {
+ profile: atom({
+ key: "profile",
+ default: null,
+ }),
+ tweets: atom({
+ key: "tweets",
+ default: null,
+ }),
+ filteredTweets: atom({
+ key: "filteredTweets",
+ default: null,
+ }),
+ showCreateTweetModal: atom({
+ key: "showCreateTweetModal",
+ default: false,
+ }),
+ modalMessage: atom({
+ key: "modalMessage",
+ default: "",
+ }),
+ createTweetLoading: atom({
+ key: "createTweetLoading",
+ default: false,
+ }),
+ createTweetSuccessful: atom({
+ key: "createTweetSuccessful",
+ default: null,
+ }),
+ updateProfileLoading: atom({
+ key: "updateProfileLoading",
+ default: false,
+ }),
+ updateProfileSuccess: atom({
+ key: "updateProfileSuccess",
+ default: null,
+ }),
+};
diff --git a/phone/src/apps/twitter/hooks/useFilteredTweets.js b/phone/src/apps/twitter/hooks/useFilteredTweets.js
new file mode 100644
index 0000000..e1fbebe
--- /dev/null
+++ b/phone/src/apps/twitter/hooks/useFilteredTweets.js
@@ -0,0 +1,7 @@
+import { useRecoilState } from "recoil";
+import { twitterState } from "./state";
+
+export const useFilteredTweets = () => {
+ const [tweets, setTweets] = useRecoilState(twitterState.filteredTweets);
+ return { tweets, setTweets };
+};
diff --git a/phone/src/apps/twitter/hooks/useModal.js b/phone/src/apps/twitter/hooks/useModal.js
new file mode 100644
index 0000000..763956e
--- /dev/null
+++ b/phone/src/apps/twitter/hooks/useModal.js
@@ -0,0 +1,10 @@
+import { useRecoilState } from "recoil";
+import { twitterState } from "./state";
+
+export const useModal = () => {
+ const [modalVisible, setModalVisible] = useRecoilState(
+ twitterState.showCreateTweetModal
+ );
+ const [message, setMessage] = useRecoilState(twitterState.modalMessage);
+ return { modalVisible, setModalVisible, message, setMessage };
+};
diff --git a/phone/src/apps/twitter/hooks/useProfile.js b/phone/src/apps/twitter/hooks/useProfile.js
new file mode 100644
index 0000000..a8982e5
--- /dev/null
+++ b/phone/src/apps/twitter/hooks/useProfile.js
@@ -0,0 +1,18 @@
+import { useRecoilValue, useRecoilState } from "recoil";
+import { twitterState } from "./state";
+
+export const useProfile = () => {
+ const profile = useRecoilValue(twitterState.profile);
+ const updateProfileLoading = useRecoilValue(
+ twitterState.updateProfileLoading
+ );
+ const [updateProfileSuccessful, setUpdateProfileSuccessful] = useRecoilState(
+ twitterState.updateProfileSuccess
+ );
+ return {
+ profile,
+ updateProfileLoading,
+ updateProfileSuccessful,
+ setUpdateProfileSuccessful,
+ };
+};
diff --git a/phone/src/apps/twitter/hooks/useTweetStatus.js b/phone/src/apps/twitter/hooks/useTweetStatus.js
new file mode 100644
index 0000000..f8116da
--- /dev/null
+++ b/phone/src/apps/twitter/hooks/useTweetStatus.js
@@ -0,0 +1,15 @@
+import { useRecoilValue, useRecoilState } from "recoil";
+
+import { twitterState } from "./state";
+
+export const useTweetStatus = () => {
+ const createTweetLoading = useRecoilValue(twitterState.createTweetLoading);
+ const [createTweetSuccessful, setCreateTweetSuccessful] = useRecoilState(
+ twitterState.createTweetSuccessful
+ );
+ return {
+ createTweetLoading,
+ createTweetSuccessful,
+ setCreateTweetSuccessful,
+ };
+};
diff --git a/phone/src/apps/twitter/hooks/useTweets.js b/phone/src/apps/twitter/hooks/useTweets.js
new file mode 100644
index 0000000..7b24c1c
--- /dev/null
+++ b/phone/src/apps/twitter/hooks/useTweets.js
@@ -0,0 +1,7 @@
+import { useRecoilValue, useSetRecoilState } from "recoil";
+import { twitterState } from "./state";
+
+export const useTweets = () => {
+ const tweets = useRecoilValue(twitterState.tweets);
+ return { tweets };
+};
diff --git a/phone/src/apps/twitter/hooks/useTwitterService.js b/phone/src/apps/twitter/hooks/useTwitterService.js
new file mode 100644
index 0000000..7e37b46
--- /dev/null
+++ b/phone/src/apps/twitter/hooks/useTwitterService.js
@@ -0,0 +1,72 @@
+import { useSetRecoilState } from "recoil";
+import { v4 as uuidv4 } from "uuid";
+
+import { useNuiEvent } from "../../../os/nui-events/hooks/useNuiEvent";
+import { IMAGE_DELIMITER } from "../utils/images";
+import { APP_TWITTER } from "../utils/constants";
+import { twitterState } from "./state";
+
+/**
+ * Perform all necessary processing/transforms from the raw database
+ * data to what the frontend expects
+ * @param {object} tweet - full JSON returned from the server/database
+ */
+function processTweet(tweet) {
+ // we store images in the database as a varchar field with
+ // comma separated links to images, so here we split them
+ // back into their distinct members
+ const imageLinks = tweet.images ? tweet.images.split(IMAGE_DELIMITER) : [];
+ const images = imageLinks.map((link) => ({ id: uuidv4(), link }));
+ return { ...tweet, images };
+}
+
+/**
+ * Service to handle all NUI <> client interactions. We take
+ * this opportunity to act as a middleware layer between the
+ * client and the react components. Because I'm terrible with lua
+ * I have given up on parsing/cleaning database query results there
+ * there and have moved that logic here instead.
+ */
+export const useTwitterService = () => {
+ const setProfile = useSetRecoilState(twitterState.profile);
+ const setUpdateProfileLoading = useSetRecoilState(
+ twitterState.updateProfileLoading
+ );
+ const setUpdateProfileSuccess = useSetRecoilState(
+ twitterState.updateProfileSuccess
+ );
+ const setTweets = useSetRecoilState(twitterState.tweets);
+ const setFilteredTweets = useSetRecoilState(twitterState.filteredTweets);
+ const setCreateLoading = useSetRecoilState(twitterState.createTweetLoading);
+ const setCreateSuccess = useSetRecoilState(
+ twitterState.createTweetSuccessful
+ );
+
+ const _setProfile = (profile) => {
+ setProfile(profile[0]); // server returns an array of 1 profile
+ };
+ const _setUpdateProfileSuccess = (isSuccessful) => {
+ setUpdateProfileSuccess(isSuccessful);
+ setUpdateProfileLoading(false); // on any result we should set loading to false
+ };
+
+ const _setCreateSuccess = (isSuccessful) => {
+ setCreateSuccess(isSuccessful);
+ setCreateLoading(false);
+ };
+
+ const _setTweets = (tweets) => {
+ setTweets(tweets.map(processTweet));
+ };
+ const _setFilteredTweets = (tweets) => {
+ setFilteredTweets(tweets.map(processTweet));
+ };
+
+ useNuiEvent(APP_TWITTER, "getOrCreateTwitterProfile", _setProfile);
+ useNuiEvent(APP_TWITTER, "updateProfileLoading", setUpdateProfileLoading);
+ useNuiEvent(APP_TWITTER, "updateProfileResult", _setUpdateProfileSuccess);
+ useNuiEvent(APP_TWITTER, "fetchTweets", _setTweets);
+ useNuiEvent(APP_TWITTER, "fetchTweetsFiltered", _setFilteredTweets);
+ useNuiEvent(APP_TWITTER, "createTweetLoading", setCreateLoading);
+ useNuiEvent(APP_TWITTER, "createTweetResult", _setCreateSuccess);
+};
diff --git a/phone/src/apps/twitter/utils/constants.js b/phone/src/apps/twitter/utils/constants.js
new file mode 100644
index 0000000..6558f91
--- /dev/null
+++ b/phone/src/apps/twitter/utils/constants.js
@@ -0,0 +1,3 @@
+export const IMG_DEFAULT_AVATAR = "./media/twitter/egg.png";
+export const IMG_INVALID_AVATAR = "./media/twitter/invalid.png";
+export const APP_TWITTER = "TWITTER";
diff --git a/phone/src/apps/twitter/utils/images.js b/phone/src/apps/twitter/utils/images.js
new file mode 100644
index 0000000..a06b0b9
--- /dev/null
+++ b/phone/src/apps/twitter/utils/images.js
@@ -0,0 +1,20 @@
+// this is a hack. We are saving images in the database as
+// delimiter separated URLS, but most common delimiters (comma, pipe
+// hash, etc.) are often found in URLS (even though it's not technically
+// within specification). To get around this we have our own delimiter
+// here we'll use to join and split these strings
+export const IMAGE_DELIMITER = "||!||";
+
+/**
+ * Validate that the URL successfully loads in the browser
+ * @param {string} link - a URL we are trying to validate
+ * @param {func} onSuccess - callback if the link is valid
+ */
+export function withValidImage(link, onSuccess) {
+ const image = new Image();
+ image.onload = onSuccess;
+ image.onerror = () => {
+ console.warn(`Invalid image submitted: ${link}`);
+ };
+ image.src = link;
+}
diff --git a/phone/src/apps/twitter/utils/time.js b/phone/src/apps/twitter/utils/time.js
new file mode 100644
index 0000000..b01953f
--- /dev/null
+++ b/phone/src/apps/twitter/utils/time.js
@@ -0,0 +1,25 @@
+const ONE_MINUTE = 60;
+const ONE_HOUR = 60 * ONE_MINUTE;
+const ONE_DAY = 24 * ONE_HOUR;
+
+const JUST_NOW = "APPS_TWITTER_TIME_JUST_NOW";
+const MINUTES = "APPS_TWITTER_TIME_MINUTES";
+const HOURS = "APPS_TWITTER_TIME_HOURS";
+const DAYS = "APPS_TWITTER_TIME_DAYS";
+
+/**
+ * Convert seconds to a human readable format i.e. "Just Now", "2m", "3d"
+ * @param {function} t - translation object passed from a component implementing the hook
+ * @param {number} seconds - seconds to translate to a string
+ */
+export function secondsToHumanReadable(t, seconds) {
+ if (seconds < 60) {
+ return t(JUST_NOW);
+ } else if (seconds < ONE_HOUR) {
+ return `${Math.floor(seconds / ONE_MINUTE)}${t(MINUTES)}`;
+ } else if (seconds < ONE_DAY) {
+ return `${Math.floor(seconds / ONE_HOUR)}${t(HOURS)}`;
+ } else {
+ return `${Math.floor(seconds / ONE_DAY)}${t(DAYS)}`;
+ }
+}
diff --git a/phone/src/locale/en.json b/phone/src/locale/en.json
index ee502d1..a9fe2a9 100644
--- a/phone/src/locale/en.json
+++ b/phone/src/locale/en.json
@@ -12,6 +12,29 @@
"APPS_BANK_WITHDRAW": "Withdraw",
"APPS_BANK_TRANSFER": "Transfer",
"APPS_SETTINGS_OPTIONS_WALLPAPER": "Wallpaper",
- "APPS_SETTINGS_OPTIONS_FRAME": "Frame"
+ "APPS_SETTINGS_OPTIONS_FRAME": "Frame",
+ "APPS_TWITTER": "Twitter",
+ "APPS_TWITTER_TWEET": "Tweet",
+ "APPS_TWITTER_TWEET_MESSAGE_PLACEHOLDER": "What's happening?",
+ "APPS_TWITTER_IMAGE_PLACEHOLDER": "A link to your image or gif",
+ "APPS_TWITTER_SUBMIT_IMAGE": "Add Media",
+ "APPS_TWITTER_CLOSE_IMAGE": "Close",
+ "APPS_TWITTER_CLOSE": "Close",
+ "APPS_TWITTER_SEARCH_TWEETS": "Search for tweets",
+ "APPS_TWITTER_SEARCH_TWEETS_PLACEHOLDER": "Search by profile name or message",
+ "APPS_TWITTER_TWEET_MESSAGE_CHAR_LIMIT": "Message is over the character limit",
+ "APPS_TWITTER_CREATE_SUCCESS": "Successfully sent your tweet",
+ "APPS_TWITTER_CREATE_FAILED": "Failed to send your tweet",
+ "APPS_TWITTER_EDIT_PROFILE_AVATAR": "Avatar URL",
+ "APPS_TWITTER_EDIT_PROFILE_NAME": "Profile name",
+ "APPS_TWITTER_EDIT_PROFILE_BIO": "Bio",
+ "APPS_TWITTER_EDIT_PROFILE_LOCATION": "Location",
+ "APPS_TWITTER_EDIT_PROFILE_JOB": "Job",
+ "APPS_TWITTER_EDIT_PROFILE_SUCCESS": "Successfully updated your profile",
+ "APPS_TWITTER_EDIT_PROFILE_FAILURE": "Failed to update your profile",
+ "APPS_TWITTER_TIME_JUST_NOW": "Just now",
+ "APPS_TWITTER_TIME_MINUTES": "m",
+ "APPS_TWITTER_TIME_HOURS": "h",
+ "APPS_TWITTER_TIME_DAYS": "d"
}
}
diff --git a/phone/src/os/apps/hooks/useApps.js b/phone/src/os/apps/hooks/useApps.js
index 623eab6..dbdec36 100644
--- a/phone/src/os/apps/hooks/useApps.js
+++ b/phone/src/os/apps/hooks/useApps.js
@@ -2,6 +2,7 @@ import React from "react";
import { useConfig } from "../../../config/hooks/useConfig";
import {
blue,
+ common,
grey,
green,
orange,
@@ -14,6 +15,7 @@ import PhoneIcon from "@material-ui/icons/Phone";
import CalendarTodayIcon from "@material-ui/icons/CalendarToday";
import AccountBalanceIcon from "@material-ui/icons/AccountBalance";
import MessageIcon from "@material-ui/icons/Message";
+import TwitterIcon from "@material-ui/icons/Twitter";
import { atom } from "recoil";
import { CalculatorIcon } from "../../../apps/calculator/components/CalculatorIcon";
import { Route } from "react-router-dom";
@@ -23,6 +25,7 @@ import { CalculatorApp } from "../../../apps/calculator/components/CalculatorApp
import { SettingsApp } from "../../../apps/settings/components/SettingsApp";
import { BankApp } from "../../../apps/bank/components/BankApp";
import { MessagesApp } from "../../../apps/messages/components/MessagesApp";
+import { TwitterApp } from "../../../apps/twitter/components/TwitterApp";
import { ExampleApp } from "../../../apps/example/components/ExampleApp";
const appsState = atom({
@@ -83,6 +86,15 @@ const appsState = atom({
path: "/bank",
Route: () => ,
},
+ {
+ id: "TWITTER",
+ nameLocale: "APPS_TWITTER",
+ icon: ,
+ backgroundColor: blue[600],
+ color: common.white,
+ path: "/twitter",
+ Route: () => ,
+ },
{
id: "EXAMPLE",
nameLocale: "APPS_EXAMPLE",
diff --git a/phone/src/os/nui-events/hooks/useNuiEvent.js b/phone/src/os/nui-events/hooks/useNuiEvent.js
index 0d5469b..f56b73d 100644
--- a/phone/src/os/nui-events/hooks/useNuiEvent.js
+++ b/phone/src/os/nui-events/hooks/useNuiEvent.js
@@ -10,14 +10,15 @@ export const useNuiEvent = (app, method, handler, options = {}) => {
}, [handler]);
useEffect(() => {
+ const eventName = eventNameFactory(app, method);
const eventListener = (event) => {
if (savedHandler.current && savedHandler.current.call) {
const { data } = event;
+ console.log(eventName, data);
savedHandler.current(data);
}
};
const opts = { capture, passive, once };
- const eventName = eventNameFactory(app, method);
window.addEventListener(eventName, eventListener, opts);
return () => window.removeEventListener(eventName, eventListener, opts);
}, [app, method, capture, passive, once]);
diff --git a/phone/src/os/phone/hooks/state.js b/phone/src/os/phone/hooks/state.js
index 041521d..f978ba3 100644
--- a/phone/src/os/phone/hooks/state.js
+++ b/phone/src/os/phone/hooks/state.js
@@ -5,4 +5,8 @@ export const phoneState = {
key: "phoneVisibility",
default: false,
}),
+ phoneConfig: atom({
+ key: "phoneConfig",
+ default: null,
+ }),
};
diff --git a/phone/src/os/phone/hooks/usePhone.js b/phone/src/os/phone/hooks/usePhone.js
index baac5ef..2164ed3 100644
--- a/phone/src/os/phone/hooks/usePhone.js
+++ b/phone/src/os/phone/hooks/usePhone.js
@@ -3,5 +3,6 @@ import { phoneState } from "./state";
export const usePhone = () => {
const visibility = useRecoilValue(phoneState.visibility);
- return { visibility };
+ const config = useRecoilValue(phoneState.phoneConfig);
+ return { visibility, config };
};
diff --git a/phone/src/os/phone/hooks/usePhoneService.js b/phone/src/os/phone/hooks/usePhoneService.js
index a425585..528340e 100644
--- a/phone/src/os/phone/hooks/usePhoneService.js
+++ b/phone/src/os/phone/hooks/usePhoneService.js
@@ -5,6 +5,8 @@ import { usePhone } from "./usePhone";
export const usePhoneService = () => {
const setVisibility = useSetRecoilState(phoneState.visibility);
+ const setPhoneConfig = useSetRecoilState(phoneState.phoneConfig);
useNuiEvent("PHONE", "setVisibility", setVisibility);
+ useNuiEvent("PHONE", "phoneConfig", setPhoneConfig);
return usePhone();
};
diff --git a/phone/src/ui/components/AppContent.js b/phone/src/ui/components/AppContent.js
index 168747f..570f5e2 100644
--- a/phone/src/ui/components/AppContent.js
+++ b/phone/src/ui/components/AppContent.js
@@ -8,6 +8,7 @@ const useStyles = makeStyles((theme) => ({
},
box: {
width: "100%",
+ height: "100%", // allow application to fill entireity of space
position: "relative",
overflow: "auto",
},
@@ -17,6 +18,7 @@ const useStyles = makeStyles((theme) => ({
},
paper: {
width: "100%",
+ height: "100%", // allow application to fill entireity of space
},
}));
diff --git a/phone/src/ui/components/Modal.js b/phone/src/ui/components/Modal.js
index e69de29..c7fcfed 100644
--- a/phone/src/ui/components/Modal.js
+++ b/phone/src/ui/components/Modal.js
@@ -0,0 +1,56 @@
+import React, { useEffect } from "react";
+import { makeStyles } from "@material-ui/core/styles";
+import { Paper } from "@material-ui/core";
+
+const useStyles = makeStyles((theme) => ({
+ root: {
+ zIndex: 10,
+ background: "#424242",
+ marginTop: "15px",
+ width: "90%",
+ display: "flex",
+ flexFlow: "column nowrap",
+ position: "absolute",
+ top: "80px",
+ },
+ displayBlock: {
+ /*Sets modal to center*/
+ display: "flex",
+ flexFlow: "column nowrap",
+ justifyContent: "center",
+ alignItems: "center",
+ position: "relative",
+ },
+ displayNone: {
+ display: "none",
+ },
+}));
+
+export const Modal = ({ children, visible, handleClose }) => {
+ const classes = useStyles();
+
+ // when the user presses escape we should close the modal
+ const _handleEscape = (e) => {
+ const isEscapeKey = e.key == "Escape" || e.key == "Esc";
+ if (isEscapeKey) {
+ e.preventDefault();
+ handleClose();
+ }
+ };
+ useEffect(() => {
+ const listener = window.addEventListener("keydown", _handleEscape, true);
+ return () => window.removeEventListener("keydown", listener);
+ }, []);
+
+ const showHideClassName = visible
+ ? classes.displayBlock
+ : classes.displayNone;
+
+ return (
+
+ );
+};
+
+export default Modal;
diff --git a/phone/yarn.lock b/phone/yarn.lock
index b127ba9..9d9072b 100644
--- a/phone/yarn.lock
+++ b/phone/yarn.lock
@@ -1470,6 +1470,17 @@
dependencies:
"@babel/runtime" "^7.4.4"
+"@material-ui/lab@^4.0.0-alpha.56":
+ version "4.0.0-alpha.56"
+ resolved "https://registry.yarnpkg.com/@material-ui/lab/-/lab-4.0.0-alpha.56.tgz#ff63080949b55b40625e056bbda05e130d216d34"
+ integrity sha512-xPlkK+z/6y/24ka4gVJgwPfoCF4RCh8dXb1BNE7MtF9bXEBLN/lBxNTK8VAa0qm3V2oinA6xtUIdcRh0aeRtVw==
+ dependencies:
+ "@babel/runtime" "^7.4.4"
+ "@material-ui/utils" "^4.10.2"
+ clsx "^1.0.4"
+ prop-types "^15.7.2"
+ react-is "^16.8.0"
+
"@material-ui/styles@^4.10.0":
version "4.10.0"
resolved "https://registry.yarnpkg.com/@material-ui/styles/-/styles-4.10.0.tgz#2406dc23aa358217aa8cc772e6237bd7f0544071"
@@ -4362,6 +4373,14 @@ elliptic@^6.5.3:
minimalistic-assert "^1.0.0"
minimalistic-crypto-utils "^1.0.0"
+emoji-mart@^3.0.0:
+ version "3.0.0"
+ resolved "https://registry.yarnpkg.com/emoji-mart/-/emoji-mart-3.0.0.tgz#eca24a04881e27752a6921e09f65a86ce8539a50"
+ integrity sha512-r5DXyzOLJttdwRYfJmPq/XL3W5tiAE/VsRnS0Hqyn27SqPA/GOYwVUSx50px/dXdJyDSnvmoPbuJ/zzhwSaU4A==
+ dependencies:
+ "@babel/runtime" "^7.0.0"
+ prop-types "^15.6.0"
+
emoji-regex@^7.0.1, emoji-regex@^7.0.2:
version "7.0.3"
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-7.0.3.tgz#933a04052860c85e83c122479c4748a8e4c72156"
@@ -9304,7 +9323,7 @@ prompts@^2.0.1:
kleur "^3.0.3"
sisteransi "^1.0.4"
-prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2:
+prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2:
version "15.7.2"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==
@@ -11415,6 +11434,11 @@ uuid@^3.3.2, uuid@^3.4.0:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==
+uuid@^8.3.0:
+ version "8.3.0"
+ resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.0.tgz#ab738085ca22dc9a8c92725e459b1d507df5d6ea"
+ integrity sha512-fX6Z5o4m6XsXBdli9g7DtWgAx+osMsRRZFKma1mIUsLCz6vRvv+pz5VNbyu9UEDzpMWulZfvpgb/cmDXVulYFQ==
+
v8-compile-cache@^2.0.3, v8-compile-cache@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.1.1.tgz#54bc3cdd43317bca91e35dcaf305b1a7237de745"
diff --git a/resources/client/cl_main.lua b/resources/client/cl_main.lua
index 3b7ce3d..5e4b4da 100644
--- a/resources/client/cl_main.lua
+++ b/resources/client/cl_main.lua
@@ -149,6 +149,18 @@ function noPhone()
ESX.ShowNotification('Oi Mate, No El Telephono')
end
+function sendPhoneConfig()
+ ESX.TriggerServerCallback('phone:phoneConfig', function(config)
+ SendNUIMessage(
+ {
+ app = "PHONE",
+ method = "phoneConfig",
+ data = config
+ }
+ )
+ end)
+end
+
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
@@ -158,6 +170,7 @@ Citizen.CreateThread(function()
end
end)
+
function Phone() --Open/close phone
if Config.PhoneAsItem == true then
--print("ConfigOn")
@@ -178,6 +191,7 @@ function Phone() --Open/close phone
data = true
}
)
+ sendPhoneConfig()
SetNuiFocus(true, true)
else
isPhoneOpen = false
@@ -213,6 +227,7 @@ function Phone() --Open/close phone
data = true
}
)
+ sendPhoneConfig()
SetNuiFocus(true, true)
else
isPhoneOpen = false
@@ -234,7 +249,6 @@ RegisterCommand('phone', function(source) -- Toggles Phone
Phone()
end, false)
-
RegisterNetEvent('phone:send')
AddEventHandler('phone:send', function()
TriggerEvent('phone:sendContacts')
diff --git a/resources/client/cl_twitter.lua b/resources/client/cl_twitter.lua
new file mode 100644
index 0000000..afc7dc8
--- /dev/null
+++ b/resources/client/cl_twitter.lua
@@ -0,0 +1,79 @@
+ESX = nil
+
+Citizen.CreateThread(function()
+ while ESX == nil do
+ TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
+ Citizen.Wait(0)
+ end
+end)
+
+local APP_NAME = 'TWITTER'
+
+function sendTwitterMessage(method, data)
+ SendNUIMessage(
+ {
+ app = APP_NAME,
+ method = method,
+ data = data
+ }
+ )
+end
+
+RegisterNetEvent('phone:fetchTweets')
+AddEventHandler('phone:fetchTweets', function()
+ ESX.TriggerServerCallback('phone:fetchTweets', function(tweets)
+ sendTwitterMessage('fetchTweets', tweets)
+ end)
+end)
+
+RegisterNetEvent('phone:fetchTweetsFiltered')
+AddEventHandler('phone:fetchTweetsFiltered', function(searchValue)
+ ESX.TriggerServerCallback('phone:fetchTweetsFiltered', function(tweets)
+ sendTwitterMessage('fetchTweetsFiltered', tweets)
+ end, searchValue)
+end)
+
+
+RegisterNUICallback('phone:fetchTweets', function()
+ TriggerEvent('phone:fetchTweets')
+end)
+
+
+RegisterNUICallback('phone:fetchTweetsFiltered', function(searchValue)
+ TriggerEvent('phone:fetchTweetsFiltered', searchValue)
+end)
+
+
+RegisterNUICallback('phone:createTweet', function(data)
+ sendTwitterMessage('createTweetLoading', true)
+ ESX.TriggerServerCallback('phone:createTweet', function(isSuccessful)
+ sendTwitterMessage('createTweetResult', isSuccessful)
+ TriggerEvent('phone:fetchTweets')
+ end, data)
+end)
+
+
+function getOrCreateTwitterProfile()
+ ESX.TriggerServerCallback('phone:getOrCreateTwitterProfile', function(profile)
+ sendTwitterMessage('getOrCreateTwitterProfile', profile)
+ end)
+end
+
+-- called directly from the UI on app load
+RegisterNUICallback('phone:getOrCreateTwitterProfile', function()
+ getOrCreateTwitterProfile()
+end)
+
+-- called during subsequent updates
+RegisterNetEvent('phone:getOrCreateTwitterProfile')
+AddEventHandler('phone:getOrCreateTwitterProfile', function()
+ getOrCreateTwitterProfile()
+end)
+
+RegisterNUICallback('phone:updateTwitterProfile', function(data)
+ sendTwitterMessage('updateProfileLoading', true)
+ ESX.TriggerServerCallback('phone:updateTwitterProfile', function(result)
+ sendTwitterMessage('updateProfileResult', result)
+ TriggerEvent('phone:getOrCreateTwitterProfile')
+ end, data)
+end)
diff --git a/resources/config.lua b/resources/config.lua
index 90db018..8867bf0 100644
--- a/resources/config.lua
+++ b/resources/config.lua
@@ -4,7 +4,7 @@ Config.Locale = 'en'
Config.KeyTogglePhone = 288 -- F1
Config.KeyTakeCall = 38 -- E
-Config.PhoneAsItem = true
+Config.PhoneAsItem = false
------
--Destroy Phone
@@ -16,4 +16,18 @@ Config.RunRate = 10 --SECONDS /// Will do the initial thread every X SECONDS to
Config.DestoryChance = 100 --PERCENT BASED /// from 0 to 100 where 100 is equal to 100% chance and 10 is equal to 10%. This is dependent on the amount above so dont set it too low.
-Config.DestroyPhoneReCheck = 3 --MINUTES /// WIll wait the check for x MINUTES as they have no phone now and have been given a destroyed phone = to the number of phones they had.
\ No newline at end of file
+Config.DestroyPhoneReCheck = 3 --MINUTES /// WIll wait the check for x MINUTES as they have no phone now and have been given a destroyed phone = to the number of phones they had.
+
+
+------
+--Twitter
+------
+Config.twitter = {}
+Config.twitter.generateProfileNameFromUsers = true -- if the player's profile name should be generated from the users.first_name and users.last_name table
+Config.twitter.characterLimit = 240 -- character limit on tweet messages
+Config.twitter.allowEdtiableProfileName = true -- whether or not players can edit their profile names
+-- Config.twitter.enableLikes = true -- whether or not players can like other player's tweets and that they are visible
+Config.twitter.enableAvatars = true -- whether or not player avatars are visible and editable
+Config.twitter.enableEmojis = true -- whether or not the emoji menu is available
+Config.twitter.enableImages = true -- whether or not links to images are rendered on the UI and if players can add new ones
+Config.twitter.maxImages = 3 -- max amount of images that can be attached to a single tweet
diff --git a/resources/html/main.js b/resources/html/main.js
index 7dffca6..2226071 100644
--- a/resources/html/main.js
+++ b/resources/html/main.js
@@ -1,9 +1,9 @@
-!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=213)}([function(e,t,n){"use strict";e.exports=n(400)},function(e,t,n){"use strict";function r(){return(r=Object.assign||function(e){for(var t=1;t=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}},function(e,t,n){"use strict";function r(e){var t,n,o="";if("string"==typeof e||"number"==typeof e)o+=e;else if("object"==typeof e)if(Array.isArray(e))for(t=0;t1&&void 0!==arguments[1]?arguments[1]:{};return function(n){var i=t.defaultTheme,u=t.withTheme,d=void 0!==u&&u,p=t.name,h=Object(o.a)(t,["defaultTheme","withTheme","name"]);var v=p,m=Object(s.a)(e,Object(r.a)({defaultTheme:i,Component:n,name:p||n.displayName,classNamePrefix:v},h)),g=a.a.forwardRef((function(e,t){e.classes;var u,l=e.innerRef,s=Object(o.a)(e,["classes","innerRef"]),h=m(Object(r.a)(Object(r.a)({},n.defaultProps),e)),v=s;return("string"==typeof p||d)&&(u=Object(f.a)()||i,p&&(v=Object(c.a)({theme:u,name:p,props:s})),d&&!v.theme&&(v.theme=u)),a.a.createElement(n,Object(r.a)({ref:l||t,classes:h},v))}));return l()(g,n),g}},p=n(52);t.a=function(e,t){return d(e,Object(r.a)({defaultTheme:p.a},t))}},function(e,t,n){"use strict";e.exports=n(409)},function(e,t,n){"use strict";function r(e,t){return function(){return null}}n.r(t),n.d(t,"chainPropTypes",(function(){return r})),n.d(t,"deepmerge",(function(){return o.a})),n.d(t,"elementAcceptingRef",(function(){return l})),n.d(t,"elementTypeAcceptingRef",(function(){return s})),n.d(t,"exactProp",(function(){return c})),n.d(t,"formatMuiErrorMessage",(function(){return f.a})),n.d(t,"getDisplayName",(function(){return y})),n.d(t,"HTMLElementType",(function(){return b})),n.d(t,"ponyfillGlobal",(function(){return w})),n.d(t,"refType",(function(){return x}));var o=n(134),i=n(5),a=n.n(i);var u=(a.a.element,function(){return null});u.isRequired=(a.a.element.isRequired,function(){return null});var l=u;var s=(i.elementType,function(){return null});n(32),n(1);function c(e){return e}var f=n(92),d=n(23),p=n(48),h=/^\s*function(?:\s|\s*\/\*.*\*\/\s*)+([^(\s/]*)\s*/;function v(e){var t="".concat(e).match(h);return t&&t[1]||""}function m(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return e.displayName||e.name||v(e)||t}function g(e,t,n){var r=m(t);return e.displayName||(""!==r?"".concat(n,"(").concat(r,")"):n)}function y(e){if(null!=e){if("string"==typeof e)return e;if("function"==typeof e)return m(e,"Component");if("object"===Object(d.a)(e))switch(e.$$typeof){case p.ForwardRef:return g(e,e.render,"ForwardRef");case p.Memo:return g(e,e.type,"memo");default:return}}}function b(e,t,n,r,o){return null}var w="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),x=a.a.oneOfType([a.a.func,a.a.object])},function(e,t){var n=e.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=n)},function(e,t){e.exports=function(e){try{return!!e()}catch(e){return!0}}},function(e,t,n){var r=n(12);e.exports=function(e){if(!r(e))throw TypeError(e+" is not an object!");return e}},function(e,t){e.exports=function(e){return"object"==typeof e?null!==e:"function"==typeof e}},function(e,t,n){"use strict";!function e(){if("undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE){0;try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(e)}catch(e){console.error(e)}}}(),e.exports=n(401)},function(e,t,n){"use strict";n.d(t,"a",(function(){return o}));var r=n(92);function o(e){if("string"!=typeof e)throw new Error(Object(r.a)(7));return e.charAt(0).toUpperCase()+e.slice(1)}},function(e,t,n){var r=n(79)("wks"),o=n(56),i=n(9).Symbol,a="function"==typeof i;(e.exports=function(e){return r[e]||(r[e]=a&&i[e]||(a?i:o)("Symbol."+e))}).store=r},function(e,t,n){var r=n(39),o=Math.min;e.exports=function(e){return e>0?o(r(e),9007199254740991):0}},function(e,t){var n=e.exports={version:"2.6.11"};"number"==typeof __e&&(__e=n)},function(e,t,n){"use strict";function r(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}n.d(t,"a",(function(){return r}))},function(e,t,n){e.exports=!n(10)((function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a}))},function(e,t,n){var r=n(11),o=n(144),i=n(49),a=Object.defineProperty;t.f=n(19)?Object.defineProperty:function(e,t,n){if(r(e),t=i(t,!0),r(n),o)try{return a(e,t,n)}catch(e){}if("get"in n||"set"in n)throw TypeError("Accessors not supported!");return"value"in n&&(e[t]=n.value),e}},function(e,t,n){"use strict";n.d(t,"c",(function(){return u})),n.d(t,"b",(function(){return s})),n.d(t,"a",(function(){return c})),n.d(t,"d",(function(){return f}));var r=n(92);function o(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;return Math.min(Math.max(t,e),n)}function i(e){if(e.type)return e;if("#"===e.charAt(0))return i(function(e){e=e.substr(1);var t=new RegExp(".{1,".concat(e.length>=6?2:1,"}"),"g"),n=e.match(t);return n&&1===n[0].length&&(n=n.map((function(e){return e+e}))),n?"rgb".concat(4===n.length?"a":"","(").concat(n.map((function(e,t){return t<3?parseInt(e,16):Math.round(parseInt(e,16)/255*1e3)/1e3})).join(", "),")"):""}(e));var t=e.indexOf("("),n=e.substring(0,t);if(-1===["rgb","rgba","hsl","hsla"].indexOf(n))throw new Error(Object(r.a)(3,e));var o=e.substring(t+1,e.length-1).split(",");return{type:n,values:o=o.map((function(e){return parseFloat(e)}))}}function a(e){var t=e.type,n=e.values;return-1!==t.indexOf("rgb")?n=n.map((function(e,t){return t<3?parseInt(e,10):e})):-1!==t.indexOf("hsl")&&(n[1]="".concat(n[1],"%"),n[2]="".concat(n[2],"%")),"".concat(t,"(").concat(n.join(", "),")")}function u(e,t){var n=l(e),r=l(t);return(Math.max(n,r)+.05)/(Math.min(n,r)+.05)}function l(e){var t="hsl"===(e=i(e)).type?i(function(e){var t=(e=i(e)).values,n=t[0],r=t[1]/100,o=t[2]/100,u=r*Math.min(o,1-o),l=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:(e+n/30)%12;return o-u*Math.max(Math.min(t-3,9-t,1),-1)},s="rgb",c=[Math.round(255*l(0)),Math.round(255*l(8)),Math.round(255*l(4))];return"hsla"===e.type&&(s+="a",c.push(t[3])),a({type:s,values:c})}(e)).values:e.values;return t=t.map((function(e){return(e/=255)<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4)})),Number((.2126*t[0]+.7152*t[1]+.0722*t[2]).toFixed(3))}function s(e,t){return e=i(e),t=o(t),"rgb"!==e.type&&"hsl"!==e.type||(e.type+="a"),e.values[3]=t,a(e)}function c(e,t){if(e=i(e),t=o(t),-1!==e.type.indexOf("hsl"))e.values[2]*=1-t;else if(-1!==e.type.indexOf("rgb"))for(var n=0;n<3;n+=1)e.values[n]*=1-t;return a(e)}function f(e,t){if(e=i(e),t=o(t),-1!==e.type.indexOf("hsl"))e.values[2]+=(100-e.values[2])*t;else if(-1!==e.type.indexOf("rgb"))for(var n=0;n<3;n+=1)e.values[n]+=(255-e.values[n])*t;return a(e)}},,function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}n.d(t,"a",(function(){return r}))},function(e,t){e.exports=function(e){return e&&e.__esModule?e:{default:e}}},function(e,t,n){"use strict";function r(e,t){for(var n=0;n=0||(o[n]=e[n]);return o}n.d(t,"a",(function(){return r}))},function(e,t,n){"use strict";function r(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}n.d(t,"a",(function(){return r}))},function(e,t,n){var r=n(9),o=n(34),i=n(33),a=n(56)("src"),u=n(218),l=(""+u).split("toString");n(17).inspectSource=function(e){return u.call(e)},(e.exports=function(e,t,n,u){var s="function"==typeof n;s&&(i(n,"name")||o(n,"name",t)),e[t]!==n&&(s&&(i(n,a)||o(n,a,e[t]?""+e[t]:l.join(String(t)))),e===r?e[t]=n:u?e[t]?e[t]=n:o(e,t,n):(delete e[t],o(e,t,n)))})(Function.prototype,"toString",(function(){return"function"==typeof this&&this[a]||u.call(this)}))},function(e,t,n){var r=n(2),o=n(10),i=n(45),a=/"/g,u=function(e,t,n,r){var o=String(i(e)),u="<"+t;return""!==n&&(u+=" "+n+'="'+String(r).replace(a,""")+'"'),u+">"+o+""+t+">"};e.exports=function(e,t){var n={};n[e]=t(u),r(r.P+r.F*o((function(){var t=""[e]('"');return t!==t.toLowerCase()||t.split('"').length>3})),"String",n)}},function(e,t,n){"use strict";function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}n.d(t,"a",(function(){return r}))},function(e,t){var n={}.hasOwnProperty;e.exports=function(e,t){return n.call(e,t)}},function(e,t,n){var r=n(20),o=n(55);e.exports=n(19)?function(e,t,n){return r.f(e,t,o(1,n))}:function(e,t,n){return e[t]=n,e}},function(e,t,n){var r=n(74),o=n(45);e.exports=function(e){return r(o(e))}},function(e,t,n){"use strict";var r=n(10);e.exports=function(e,t){return!!e&&r((function(){t?e.call(null,(function(){}),1):e.call(null)}))}},function(e,t,n){var r=n(38);e.exports=function(e,t,n){if(r(e),void 0===t)return e;switch(n){case 1:return function(n){return e.call(t,n)};case 2:return function(n,r){return e.call(t,n,r)};case 3:return function(n,r,o){return e.call(t,n,r,o)}}return function(){return e.apply(t,arguments)}}},function(e,t){e.exports=function(e){if("function"!=typeof e)throw TypeError(e+" is not a function!");return e}},function(e,t){var n=Math.ceil,r=Math.floor;e.exports=function(e){return isNaN(e=+e)?0:(e>0?r:n)(e)}},function(e,t,n){var r=n(75),o=n(55),i=n(35),a=n(49),u=n(33),l=n(144),s=Object.getOwnPropertyDescriptor;t.f=n(19)?s:function(e,t){if(e=i(e),t=a(t,!0),l)try{return s(e,t)}catch(e){}if(u(e,t))return o(!r.f.call(e,t),e[t])}},function(e,t,n){var r=n(2),o=n(17),i=n(10);e.exports=function(e,t){var n=(o.Object||{})[e]||Object[e],a={};a[e]=t(n),r(r.S+r.F*i((function(){n(1)})),"Object",a)}},function(e,t,n){var r=n(37),o=n(74),i=n(26),a=n(16),u=n(160);e.exports=function(e,t){var n=1==e,l=2==e,s=3==e,c=4==e,f=6==e,d=5==e||f,p=t||u;return function(t,u,h){for(var v,m,g=i(t),y=o(g),b=r(u,h,3),w=a(y.length),x=0,S=n?p(t,w):l?p(t,0):void 0;w>x;x++)if((d||x in y)&&(m=b(v=y[x],x,g),e))if(n)S[x]=m;else if(m)switch(e){case 3:return!0;case 5:return v;case 6:return x;case 2:S.push(v)}else if(c)return!1;return f?-1:s||c?c:S}}},function(e,t,n){"use strict";n.d(t,"a",(function(){return a}));var r=n(78);var o=n(187),i=n(93);function a(e){return function(e){if(Array.isArray(e))return Object(r.a)(e)}(e)||Object(o.a)(e)||Object(i.a)(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}},function(e,t){var n={}.toString;e.exports=function(e){return n.call(e).slice(8,-1)}},function(e,t){e.exports=function(e){if(null==e)throw TypeError("Can't call method on "+e);return e}},function(e,t,n){"use strict";if(n(19)){var r=n(57),o=n(9),i=n(10),a=n(2),u=n(90),l=n(128),s=n(37),c=n(69),f=n(55),d=n(34),p=n(70),h=n(39),v=n(16),m=n(171),g=n(59),y=n(49),b=n(33),w=n(76),x=n(12),S=n(26),E=n(120),O=n(60),k=n(62),j=n(61).f,T=n(122),C=n(56),P=n(15),R=n(42),A=n(80),N=n(77),_=n(124),M=n(67),L=n(83),I=n(68),F=n(123),z=n(162),D=n(20),V=n(40),U=D.f,B=V.f,W=o.RangeError,$=o.TypeError,H=o.Uint8Array,K=Array.prototype,q=l.ArrayBuffer,G=l.DataView,Q=R(0),Y=R(2),X=R(3),J=R(4),Z=R(5),ee=R(6),te=A(!0),ne=A(!1),re=_.values,oe=_.keys,ie=_.entries,ae=K.lastIndexOf,ue=K.reduce,le=K.reduceRight,se=K.join,ce=K.sort,fe=K.slice,de=K.toString,pe=K.toLocaleString,he=P("iterator"),ve=P("toStringTag"),me=C("typed_constructor"),ge=C("def_constructor"),ye=u.CONSTR,be=u.TYPED,we=u.VIEW,xe=R(1,(function(e,t){return je(N(e,e[ge]),t)})),Se=i((function(){return 1===new H(new Uint16Array([1]).buffer)[0]})),Ee=!!H&&!!H.prototype.set&&i((function(){new H(1).set({})})),Oe=function(e,t){var n=h(e);if(n<0||n%t)throw W("Wrong offset!");return n},ke=function(e){if(x(e)&&be in e)return e;throw $(e+" is not a typed array!")},je=function(e,t){if(!x(e)||!(me in e))throw $("It is not a typed array constructor!");return new e(t)},Te=function(e,t){return Ce(N(e,e[ge]),t)},Ce=function(e,t){for(var n=0,r=t.length,o=je(e,r);r>n;)o[n]=t[n++];return o},Pe=function(e,t,n){U(e,t,{get:function(){return this._d[n]}})},Re=function(e){var t,n,r,o,i,a,u=S(e),l=arguments.length,c=l>1?arguments[1]:void 0,f=void 0!==c,d=T(u);if(null!=d&&!E(d)){for(a=d.call(u),r=[],t=0;!(i=a.next()).done;t++)r.push(i.value);u=r}for(f&&l>2&&(c=s(c,arguments[2],2)),t=0,n=v(u.length),o=je(this,n);n>t;t++)o[t]=f?c(u[t],t):u[t];return o},Ae=function(){for(var e=0,t=arguments.length,n=je(this,t);t>e;)n[e]=arguments[e++];return n},Ne=!!H&&i((function(){pe.call(new H(1))})),_e=function(){return pe.apply(Ne?fe.call(ke(this)):ke(this),arguments)},Me={copyWithin:function(e,t){return z.call(ke(this),e,t,arguments.length>2?arguments[2]:void 0)},every:function(e){return J(ke(this),e,arguments.length>1?arguments[1]:void 0)},fill:function(e){return F.apply(ke(this),arguments)},filter:function(e){return Te(this,Y(ke(this),e,arguments.length>1?arguments[1]:void 0))},find:function(e){return Z(ke(this),e,arguments.length>1?arguments[1]:void 0)},findIndex:function(e){return ee(ke(this),e,arguments.length>1?arguments[1]:void 0)},forEach:function(e){Q(ke(this),e,arguments.length>1?arguments[1]:void 0)},indexOf:function(e){return ne(ke(this),e,arguments.length>1?arguments[1]:void 0)},includes:function(e){return te(ke(this),e,arguments.length>1?arguments[1]:void 0)},join:function(e){return se.apply(ke(this),arguments)},lastIndexOf:function(e){return ae.apply(ke(this),arguments)},map:function(e){return xe(ke(this),e,arguments.length>1?arguments[1]:void 0)},reduce:function(e){return ue.apply(ke(this),arguments)},reduceRight:function(e){return le.apply(ke(this),arguments)},reverse:function(){for(var e,t=ke(this).length,n=Math.floor(t/2),r=0;r1?arguments[1]:void 0)},sort:function(e){return ce.call(ke(this),e)},subarray:function(e,t){var n=ke(this),r=n.length,o=g(e,r);return new(N(n,n[ge]))(n.buffer,n.byteOffset+o*n.BYTES_PER_ELEMENT,v((void 0===t?r:g(t,r))-o))}},Le=function(e,t){return Te(this,fe.call(ke(this),e,t))},Ie=function(e){ke(this);var t=Oe(arguments[1],1),n=this.length,r=S(e),o=v(r.length),i=0;if(o+t>n)throw W("Wrong length!");for(;i255?255:255&r),o.v[p](n*t+o.o,r,Se)}(this,n,e)},enumerable:!0})};b?(h=n((function(e,n,r,o){c(e,h,s,"_d");var i,a,u,l,f=0,p=0;if(x(n)){if(!(n instanceof q||"ArrayBuffer"==(l=w(n))||"SharedArrayBuffer"==l))return be in n?Ce(h,n):Re.call(h,n);i=n,p=Oe(r,t);var g=n.byteLength;if(void 0===o){if(g%t)throw W("Wrong length!");if((a=g-p)<0)throw W("Wrong length!")}else if((a=v(o)*t)+p>g)throw W("Wrong length!");u=a/t}else u=m(n),i=new q(a=u*t);for(d(e,"_d",{b:i,o:p,l:a,e:u,v:new G(i)});f0&&void 0!==arguments[0]?arguments[0]:["all"],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.duration,u=void 0===n?i.standard:n,l=t.easing,s=void 0===l?o.easeInOut:l,c=t.delay,f=void 0===c?0:c;Object(r.a)(t,["duration","easing","delay"]);return(Array.isArray(e)?e:[e]).map((function(e){return"".concat(e," ").concat("string"==typeof u?u:a(u)," ").concat(s," ").concat("string"==typeof f?f:a(f))})).join(",")},getAutoHeightDuration:function(e){if(!e)return 0;var t=e/36;return Math.round(10*(4+15*Math.pow(t,.25)+t/5))}}},function(e,t){e.exports=function(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}}},function(e,t){var n=0,r=Math.random();e.exports=function(e){return"Symbol(".concat(void 0===e?"":e,")_",(++n+r).toString(36))}},function(e,t){e.exports=!1},function(e,t,n){var r=n(146),o=n(107);e.exports=Object.keys||function(e){return r(e,o)}},function(e,t,n){var r=n(39),o=Math.max,i=Math.min;e.exports=function(e,t){return(e=r(e))<0?o(e+t,0):i(e,t)}},function(e,t,n){var r=n(11),o=n(147),i=n(107),a=n(106)("IE_PROTO"),u=function(){},l=function(){var e,t=n(104)("iframe"),r=i.length;for(t.style.display="none",n(108).appendChild(t),t.src="javascript:",(e=t.contentWindow.document).open(),e.write("