This commit is contained in:
dangered wolf 2023-10-15 14:24:27 -04:00
commit d13230f05a
No known key found for this signature in database
GPG key ID: 41E4D37680ED8B58
4 changed files with 9 additions and 13 deletions

View file

@ -47,7 +47,7 @@ const populateTweetProperties = async (
/* Populating a lot of the basics */ /* Populating a lot of the basics */
apiTweet.url = `${Constants.TWITTER_ROOT}/${apiUser.screen_name}/status/${tweet.rest_id}`; apiTweet.url = `${Constants.TWITTER_ROOT}/${apiUser.screen_name}/status/${tweet.rest_id}`;
apiTweet.id = tweet.rest_id; apiTweet.id = tweet.rest_id;
apiTweet.text = unescapeText(linkFixer(tweet, tweet.legacy.full_text || '')); apiTweet.text = unescapeText(linkFixer(tweet.legacy.entities?.urls, tweet.legacy.full_text || ''));
apiTweet.author = { apiTweet.author = {
id: apiUser.id, id: apiUser.id,
name: apiUser.name, name: apiUser.name,
@ -93,7 +93,7 @@ const populateTweetProperties = async (
tweet.note_tweet?.note_tweet_results?.result?.entity_set.symbols; tweet.note_tweet?.note_tweet_results?.result?.entity_set.symbols;
console.log('We meet the conditions to use new note tweets'); console.log('We meet the conditions to use new note tweets');
apiTweet.text = unescapeText(linkFixer(tweet, noteTweetText)); apiTweet.text = unescapeText(linkFixer(tweet.legacy.entities.urls, noteTweetText));
apiTweet.is_note_tweet = true; apiTweet.is_note_tweet = true;
} else { } else {
apiTweet.is_note_tweet = false; apiTweet.is_note_tweet = false;
@ -186,7 +186,7 @@ const populateTweetProperties = async (
const translateAPI = await translateTweet(tweet, conversation.guestToken || '', language); const translateAPI = await translateTweet(tweet, conversation.guestToken || '', language);
if (translateAPI !== null && translateAPI?.translation) { if (translateAPI !== null && translateAPI?.translation) {
apiTweet.translation = { apiTweet.translation = {
text: unescapeText(linkFixer(tweet, translateAPI?.translation || '')), text: unescapeText(linkFixer(tweet.legacy?.entities?.urls, translateAPI?.translation || '')),
source_lang: translateAPI?.sourceLanguage || '', source_lang: translateAPI?.sourceLanguage || '',
target_lang: translateAPI?.destinationLanguage || '', target_lang: translateAPI?.destinationLanguage || '',
source_lang_en: translateAPI?.localizedSourceLanguage || '' source_lang_en: translateAPI?.localizedSourceLanguage || ''

View file

@ -1,5 +1,6 @@
import { Constants } from '../constants'; import { Constants } from '../constants';
import { fetchUser } from '../fetch'; import { fetchUser } from '../fetch';
import { linkFixer } from '../helpers/linkFixer';
export const convertToApiUser = (user: GraphQLUser): APIUser => { export const convertToApiUser = (user: GraphQLUser): APIUser => {
const apiUser = {} as APIUser; const apiUser = {} as APIUser;
@ -12,7 +13,7 @@ export const convertToApiUser = (user: GraphQLUser): APIUser => {
apiUser.tweets = user.legacy.statuses_count; apiUser.tweets = user.legacy.statuses_count;
apiUser.name = user.legacy.name; apiUser.name = user.legacy.name;
apiUser.screen_name = user.legacy.screen_name; apiUser.screen_name = user.legacy.screen_name;
apiUser.description = user.legacy.description; apiUser.description = linkFixer(user.legacy.entities?.description?.urls, user.legacy.description);
apiUser.location = user.legacy.location; apiUser.location = user.legacy.location;
apiUser.banner_url = user.legacy.profile_banner_url; apiUser.banner_url = user.legacy.profile_banner_url;
/* /*

View file

@ -1,10 +1,10 @@
/* Helps replace t.co links with their originals */ /* Helps replace t.co links with their originals */
export const linkFixer = (tweet: GraphQLTweet, text: string): string => { export const linkFixer = (entities: TcoExpansion[] | undefined, text: string): string => {
// console.log('got entities', { // console.log('got entities', {
// entities: tweet.legacy.entities // entities: tweet.legacy.entities
// }); // });
if (Array.isArray(tweet.legacy.entities?.urls) && tweet.legacy.entities.urls.length) { if (Array.isArray(entities) && entities.length) {
tweet.legacy.entities.urls.forEach((url: TcoExpansion) => { entities.forEach((url: TcoExpansion) => {
let newURL = url.expanded_url; let newURL = url.expanded_url;
if (newURL.match(/^https:\/\/twitter\.com\/i\/web\/status\/\w+/g) !== null) { if (newURL.match(/^https:\/\/twitter\.com\/i\/web\/status\/\w+/g) !== null) {

View file

@ -232,12 +232,7 @@ type GraphQLUser = {
description: string; // "What's happening?!", description: string; // "What's happening?!",
entities: { entities: {
description?: { description?: {
urls?: { urls?: TcoExpansion[];
display_url: string; // "about.twitter.com",
expanded_url: string; // "https://about.twitter.com/",
url: string; // "https://t.co/DAtOo6uuHk",
indices: [0, 23];
}[];
}; };
url?: { url?: {
urls?: { urls?: {