From 8ce632308e502291a560a09d7de17cb551ee6b6a Mon Sep 17 00:00:00 2001 From: dangered wolf Date: Thu, 19 Oct 2023 01:24:55 -0400 Subject: [PATCH] upstream fixes --- src/api/status.ts | 7 ++++++- src/providers/twitter/processor.ts | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/api/status.ts b/src/api/status.ts index ef129c7..9a8d4f5 100644 --- a/src/api/status.ts +++ b/src/api/status.ts @@ -16,7 +16,7 @@ const populateTweetProperties = async ( conversation: TweetResultsByRestIdResult, // TimelineBlobPartial, language: string | undefined // eslint-disable-next-line sonarjs/cognitive-complexity -): Promise => { +): Promise => { const apiTweet = {} as APITweet; /* Sometimes, Twitter returns a different kind of Tweet type called 'TweetWithVisibilityResults'. @@ -38,6 +38,11 @@ const populateTweetProperties = async ( tweet.views = tweet?.tweet?.views; } + if (typeof tweet.core === 'undefined') { + console.log('Tweet still not valid', tweet); + return null; + } + /* With v2 conversation API we re-add the user object ot the tweet because Twitter stores it separately in the conversation API. This is to consolidate it in case a user appears multiple times in a thread. */ diff --git a/src/providers/twitter/processor.ts b/src/providers/twitter/processor.ts index d28203b..3b8e1b7 100644 --- a/src/providers/twitter/processor.ts +++ b/src/providers/twitter/processor.ts @@ -13,7 +13,7 @@ export const buildAPITweet = async ( threadPiece = false, legacyAPI = false // eslint-disable-next-line sonarjs/cognitive-complexity -): Promise => { +): Promise => { const apiTweet = {} as APITweet; /* Sometimes, Twitter returns a different kind of Tweet type called 'TweetWithVisibilityResults'. @@ -35,6 +35,11 @@ export const buildAPITweet = async ( tweet.views = tweet?.tweet?.views; } + if (typeof tweet.core === 'undefined') { + console.log('Tweet still not valid', tweet); + return null; + } + const graphQLUser = tweet.core.user_results.result; const apiUser = convertToApiUser(graphQLUser); @@ -124,6 +129,16 @@ export const buildAPITweet = async ( photos: [], videos: [], }; + + /* We found a quote tweet, let's process that too */ + const quoteTweet = tweet.quoted_status_result; + if (quoteTweet) { + apiTweet.quote = (await buildAPITweet(quoteTweet, language)) as APITweet; + /* Only override the embed_card if it's a basic tweet, since media always takes precedence */ + if (apiTweet.embed_card === 'tweet'&& apiTweet.quote !== null) { + apiTweet.embed_card = apiTweet.quote.embed_card; + } + } const mediaList = Array.from( tweet.legacy.extended_entities?.media || tweet.legacy.entities?.media || []