Add TweetWithVisibilityResults support

This commit is contained in:
dangered wolf 2023-08-21 04:42:19 -04:00
parent bfc67935b4
commit 9017056c17
No known key found for this signature in database
GPG key ID: 41E4D37680ED8B58
4 changed files with 75 additions and 45 deletions

View file

@ -20,10 +20,23 @@ const populateTweetProperties = async (
): Promise<APITweet> => {
const apiTweet = {} as APITweet;
/* Sometimes, Twitter returns a different kind of Tweet type called 'TweetWithVisibilityResults'.
It has slightly different attributes from the regular 'Tweet' type. We fix that up here. */
if (typeof tweet.core === 'undefined' && typeof tweet.result !== 'undefined') {
tweet = tweet.result;
} else {
console.log('tweet core exists');
}
if (typeof tweet.core === 'undefined' && typeof tweet.tweet?.core !== 'undefined') {
tweet.core = tweet.tweet.core;
}
if (typeof tweet.legacy === 'undefined' && typeof tweet.tweet?.legacy !== 'undefined') {
tweet.legacy = tweet.tweet?.legacy;
}
if (typeof tweet.views === 'undefined' && typeof tweet?.tweet?.views !== 'undefined') {
tweet.views = tweet?.tweet?.views;
}
/* With v2 conversation API we re-add the user object ot the tweet because

View file

@ -305,27 +305,7 @@ type GraphQLUser = {
};
};
type GraphQLTweet = {
// Workaround
result: GraphQLTweet;
__typename: 'Tweet' | 'TweetUnavailable';
rest_id: string; // "1674824189176590336",
has_birdwatch_notes: false;
core: {
user_results: {
result: GraphQLUser;
};
};
edit_control: unknown;
edit_perspective: unknown;
is_translatable: false;
views: {
count: string; // "562"
state: string; // "EnabledWithCount"
};
source: string; // "<a href=\"https://mobile.twitter.com\" rel=\"nofollow\">Twitter Web App</a>"
quoted_status_result?: GraphQLTweet;
legacy: {
type GraphQLTweetLegacy = {
created_at: string; // "Tue Sep 14 20:00:00 +0000 2021"
conversation_id_str: string; // "1674824189176590336"
bookmark_count: number; // 0
@ -365,7 +345,41 @@ type GraphQLTweet = {
extended_entities: {
media: TweetMedia[];
};
};
type GraphQLTweet = {
// Workaround
result: GraphQLTweet;
__typename: 'Tweet' | 'TweetUnavailable';
rest_id: string; // "1674824189176590336",
has_birdwatch_notes: false;
core: {
user_results: {
result: GraphQLUser;
};
};
tweet?: {
legacy: GraphQLTweetLegacy;
views: {
count: string; // "562"
state: string; // "EnabledWithCount"
};
core: {
user_results: {
result: GraphQLUser;
};
}
};
edit_control: unknown;
edit_perspective: unknown;
is_translatable: false;
views: {
count: string; // "562"
state: string; // "EnabledWithCount"
};
source: string; // "<a href=\"https://mobile.twitter.com\" rel=\"nofollow\">Twitter Web App</a>"
quoted_status_result?: GraphQLTweet;
legacy: GraphQLTweetLegacy;
note_tweet: {
is_expandable: boolean;
entity_set: {

View file

@ -150,7 +150,7 @@ interface APITweet {
replies: number;
views?: number | null;
color: string;
color: string | null;
quote?: APITweet;
poll?: APIPoll;

View file

@ -15,3 +15,6 @@ command = "npm run build"
[miniflare.globals]
TEST = "true" # Will have unicode character errors in headers if not set to true
[placement]
mode = "smart"