mirror of
https://github.com/CompeyDev/fxtwitter-docker.git
synced 2025-04-05 02:20:54 +01:00
Add view counts
This commit is contained in:
parent
b8ed88ac9a
commit
23b5baae1e
5 changed files with 20 additions and 0 deletions
|
@ -49,6 +49,12 @@ const populateTweetProperties = async (
|
|||
apiTweet.created_at = tweet.created_at;
|
||||
apiTweet.created_timestamp = new Date(tweet.created_at).getTime() / 1000;
|
||||
|
||||
if (tweet.ext_views?.state === 'EnabledWithCount') {
|
||||
apiTweet.views = parseInt(tweet.ext_views.count || '0') ?? null;
|
||||
} else {
|
||||
apiTweet.views = null;
|
||||
}
|
||||
|
||||
if (tweet.lang !== 'unk') {
|
||||
apiTweet.lang = tweet.lang;
|
||||
} else {
|
||||
|
|
|
@ -26,6 +26,7 @@ export const Constants = {
|
|||
'cards_platform=Web-12',
|
||||
'include_cards=1',
|
||||
'include_ext_alt_text=true',
|
||||
'include_ext_views=true',
|
||||
'include_quote_count=true',
|
||||
'include_reply_count=1',
|
||||
'tweet_mode=extended',
|
||||
|
|
|
@ -14,6 +14,9 @@ export const getAuthorText = (tweet: APITweet): string | null => {
|
|||
if (tweet.likes > 0) {
|
||||
authorText += `${formatNumber(tweet.likes)} ❤️ `;
|
||||
}
|
||||
if (tweet.views && tweet.views > 0) {
|
||||
authorText += `${formatNumber(tweet.views)} 👁️ `;
|
||||
}
|
||||
authorText = authorText.trim();
|
||||
|
||||
return authorText;
|
||||
|
|
9
src/types/twitterTypes.d.ts
vendored
9
src/types/twitterTypes.d.ts
vendored
|
@ -128,6 +128,14 @@ type TweetEntities = {
|
|||
media?: TweetMedia[];
|
||||
};
|
||||
|
||||
/* TODO: Are there more states for ext_views?
|
||||
Legacy Tweets use Enabled but have no count, while newer tweets have EnabledWithCount
|
||||
and count is populated with a string. */
|
||||
type ExtViews = {
|
||||
state: 'Enabled' | 'EnabledWithCount',
|
||||
count?: string
|
||||
}
|
||||
|
||||
type TweetPartial = {
|
||||
card?: TweetCard;
|
||||
conversation_id_str: string;
|
||||
|
@ -135,6 +143,7 @@ type TweetPartial = {
|
|||
display_text_range: [number, number];
|
||||
entities: TweetEntities;
|
||||
extended_entities: TweetEntities;
|
||||
ext_views?: ExtViews;
|
||||
favorite_count: number;
|
||||
in_reply_to_screen_name?: string;
|
||||
in_reply_to_status_id_str?: string;
|
||||
|
|
1
src/types/types.d.ts
vendored
1
src/types/types.d.ts
vendored
|
@ -116,6 +116,7 @@ interface APITweet {
|
|||
likes: number;
|
||||
retweets: number;
|
||||
replies: number;
|
||||
views?: number | null;
|
||||
|
||||
color: string;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue