upstream fixes

This commit is contained in:
dangered wolf 2023-10-19 01:24:55 -04:00
parent 0a616e9731
commit 8ce632308e
No known key found for this signature in database
GPG key ID: 41E4D37680ED8B58
2 changed files with 22 additions and 2 deletions

View file

@ -16,7 +16,7 @@ const populateTweetProperties = async (
conversation: TweetResultsByRestIdResult, // TimelineBlobPartial,
language: string | undefined
// eslint-disable-next-line sonarjs/cognitive-complexity
): Promise<APITweet> => {
): Promise<APITweet | null> => {
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. */

View file

@ -13,7 +13,7 @@ export const buildAPITweet = async (
threadPiece = false,
legacyAPI = false
// eslint-disable-next-line sonarjs/cognitive-complexity
): Promise<APITweet> => {
): Promise<APITweet | null> => {
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 || []