From a69b1e9407120b5a6593235423fa74b3a4a7d21c Mon Sep 17 00:00:00 2001 From: dangered wolf Date: Fri, 18 Aug 2023 03:07:58 -0400 Subject: [PATCH] Implement proper IV --- src/helpers/author.ts | 25 ++++++++++++ src/render/instantview.ts | 83 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 106 insertions(+), 2 deletions(-) diff --git a/src/helpers/author.ts b/src/helpers/author.ts index e2c55fe..bf0a4a8 100644 --- a/src/helpers/author.ts +++ b/src/helpers/author.ts @@ -24,3 +24,28 @@ export const getAuthorText = (tweet: APITweet): string | null => { return null; }; + +/* The embed "author" text we populate with replies, retweets, and likes unless it's a video */ +export const getSocialTextIV = (tweet: APITweet): string | null => { + /* Build out reply, retweet, like counts */ + if (tweet.likes > 0 || tweet.retweets > 0 || tweet.replies > 0) { + let authorText = ''; + if (tweet.replies > 0) { + authorText += `💬 ${formatNumber(tweet.replies)} `; + } + if (tweet.retweets > 0) { + authorText += `🔁 ${formatNumber(tweet.retweets)} `; + } + if (tweet.likes > 0) { + authorText += `❤️ ${formatNumber(tweet.likes)} `; + } + if (tweet.views && tweet.views > 0) { + authorText += `👁️ ${formatNumber(tweet.views)} `; + } + authorText = authorText.trim(); + + return authorText; + } + + return null; +}; diff --git a/src/render/instantview.ts b/src/render/instantview.ts index d0ce96b..1e6c2a3 100644 --- a/src/render/instantview.ts +++ b/src/render/instantview.ts @@ -1,3 +1,55 @@ +import { Constants } from "../constants"; +import { getSocialTextIV } from "../helpers/author"; +import { sanitizeText } from "../helpers/utils"; + +const populateUserLinks = (tweet: APITweet, text: string): string => { + /* TODO: Maybe we can add username splices to our API so only genuinely valid users are linked? */ + text.match(/@(\w{1,15})/g)?.forEach((match) => { + const username = match.replace('@', ''); + text = text.replace( + match, + `${match}` + ); + }); + return text; +} + +const generateTweetMedia = (tweet: APITweet): string => { + let media = ''; + if (tweet.media?.all?.length) { + tweet.media.all.forEach((mediaItem) => { + switch(mediaItem.type) { + case 'photo': + media += `${tweet.author.name}'s photo`; + break; + case 'video': + media += `