-
-
-
+
+
+
+
+
+
+
} secondary={
} />
+
+
+
+
+
);
diff --git a/phone/src/apps/twitter/components/TweetList.js b/phone/src/apps/twitter/components/TweetList.js
index 6b4ad94..a8e21f7 100644
--- a/phone/src/apps/twitter/components/TweetList.js
+++ b/phone/src/apps/twitter/components/TweetList.js
@@ -28,11 +28,9 @@ export function TweetList() {
return (
- {tweets
- .filter((t) => t.visible)
- .map((tweet) => (
-
- ))}
+ {tweets.map((tweet) => (
+
+ ))}
);
}
diff --git a/phone/src/apps/twitter/components/TwitterApp.js b/phone/src/apps/twitter/components/TwitterApp.js
index 44ab090..e81295a 100644
--- a/phone/src/apps/twitter/components/TwitterApp.js
+++ b/phone/src/apps/twitter/components/TwitterApp.js
@@ -15,6 +15,7 @@ import { useProfile } from "../hooks/useProfile";
import "./twitter.css";
+// TODO move this to the router so the application back button works
const PAGE_COMPONENT_MAPPING = {
0:
,
1:
,
@@ -25,7 +26,7 @@ const MINIMUM_LOAD_TIME = 750;
export const TwitterApp = () => {
const [minimumLoadPassed, setMimimumLoadPassed] = useState(false);
const [modalVisible, setModalVisible] = useState(false);
- const [activePage, setActivePage] = useState(2);
+ const [activePage, setActivePage] = useState(0);
const { profile } = useProfile();
useEffect(() => {
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 172a20c..fb2541c 100644
--- a/phone/src/locale/en.json
+++ b/phone/src/locale/en.json
@@ -24,6 +24,10 @@
"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_JOB": "Job",
+ "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/resources/server/sv_twitter.lua b/resources/server/sv_twitter.lua
index cefcd75..fc121ff 100644
--- a/resources/server/sv_twitter.lua
+++ b/resources/server/sv_twitter.lua
@@ -11,10 +11,24 @@ TriggerEvent('esx:getSharedObject', function(obj)
end)
ESX.RegisterServerCallback('phone:fetchTweets', function(source, cb)
- local _source = source
- local xPlayer = ESX.GetPlayerFromId(_source)
- local _identifier = xPlayer.getIdentifier()
- MySQL.Async.fetchAll('SELECT * FROM npwd_twitter_tweets WHERE visible = 1 ORDER BY updatedAt DESC', {}, function(tweets)
+ MySQL.Async.fetchAll([[
+ SELECT
+ npwd_twitter_tweets.id,
+ npwd_twitter_tweets.createdAt,
+ npwd_twitter_tweets.likes,
+ npwd_twitter_tweets.identifier,
+ npwd_twitter_tweets.visible,
+ npwd_twitter_tweets.images,
+ npwd_twitter_tweets.message,
+ npwd_twitter_profiles.profile_name,
+ npwd_twitter_profiles.avatar_url,
+ TIME_TO_SEC(TIMEDIFF( NOW(), npwd_twitter_tweets.createdAt)) AS seconds_since_tweet
+ FROM npwd_twitter_tweets
+ LEFT OUTER JOIN npwd_twitter_profiles ON npwd_twitter_tweets.identifier = npwd_twitter_profiles.identifier
+ WHERE visible = 1
+ ORDER BY npwd_twitter_tweets.createdAt DESC
+ LIMIT 75
+ ]], {}, function(tweets)
cb(tweets)
end)
end)