Add limited note tweet support

This commit is contained in:
dangered wolf 2023-08-17 02:55:12 -04:00
parent 7306302051
commit f47f298f34
No known key found for this signature in database
GPG key ID: 41E4D37680ED8B58
3 changed files with 28 additions and 5 deletions

View file

@ -104,6 +104,16 @@ const populateTweetProperties = async (
apiTweet.color = colorFromPalette(mediaList[0].ext_media_color.palette); apiTweet.color = colorFromPalette(mediaList[0].ext_media_color.palette);
} }
*/ */
console.log('note_tweet', JSON.stringify(tweet.note_tweet));
console.log('note tweet text', tweet.note_tweet?.note_tweet_results?.result?.text)
console.log('mediaList.length <= 0', mediaList.length <= 0)
console.log('tweet.legacy.entities?.urls?.length <= 0', tweet.legacy.entities?.urls?.length <= 0)
const noteTweetText = tweet.note_tweet?.note_tweet_results?.result?.text;
/* For now, don't include note tweets */
if (noteTweetText && mediaList.length <= 0 && tweet.legacy.entities?.urls?.length <= 0) {
console.log('We meet the conditions to use new note tweets');
apiTweet.text = unescapeText(noteTweetText);
}
/* Handle photos and mosaic if available */ /* Handle photos and mosaic if available */
if ((apiTweet.media?.photos?.length || 0) > 1) { if ((apiTweet.media?.photos?.length || 0) > 1) {
@ -211,10 +221,10 @@ export const statusAPI = async (
if (tweet.reason === 'Protected') { if (tweet.reason === 'Protected') {
writeDataPoint(event, language, wasMediaBlockedNSFW, 'PRIVATE_TWEET', flags); writeDataPoint(event, language, wasMediaBlockedNSFW, 'PRIVATE_TWEET', flags);
return { code: 401, message: 'PRIVATE_TWEET' }; return { code: 401, message: 'PRIVATE_TWEET' };
} else if (tweet.reason === 'NsfwLoggedOut') { // } else if (tweet.reason === 'NsfwLoggedOut') {
// API failure as elongator should have handled this // // API failure as elongator should have handled this
writeDataPoint(event, language, wasMediaBlockedNSFW, 'API_FAIL', flags); // writeDataPoint(event, language, wasMediaBlockedNSFW, 'API_FAIL', flags);
return { code: 500, message: 'API_FAIL' }; // return { code: 500, message: 'API_FAIL' };
} else { } else {
// Api failure at parsing status // Api failure at parsing status
writeDataPoint(event, language, wasMediaBlockedNSFW, 'API_FAIL', flags); writeDataPoint(event, language, wasMediaBlockedNSFW, 'API_FAIL', flags);

View file

@ -295,7 +295,7 @@ export const handleStatus = async (
/* Push basic headers relating to author, Tweet text, and site name */ /* Push basic headers relating to author, Tweet text, and site name */
headers.push( headers.push(
`<meta property="og:title" content="${tweet.author.name} (@${tweet.author.screen_name})"/>`, `<meta property="og:title" content="${tweet.author.name} (@${tweet.author.screen_name})"/>`,
`<meta property="og:description" content="${sanitizeText(newText)}"/>`, `<meta property="og:description" content="${sanitizeText(newText).replace(/\n/g, '<br>')}"/>`,
`<meta property="og:site_name" content="${siteName}"/>` `<meta property="og:site_name" content="${siteName}"/>`
); );

View file

@ -366,6 +366,19 @@ type GraphQLTweet = {
media: TweetMedia[] media: TweetMedia[]
} }
} }
note_tweet: {
is_expandable: boolean;
entity_set: {
hashtags: unknown[];
urls: unknown[];
user_mentions: unknown[];
},
note_tweet_results: {
result: {
text: string;
}
}
};
card: { card: {
rest_id: string; // "card://1674824189176590336", rest_id: string; // "card://1674824189176590336",
legacy: { legacy: {