Show the original tweet firstly

This commit is contained in:
Hongbo Wu 2022-10-10 15:33:36 +08:00
parent 5d70d04154
commit 08c30f9c24

View file

@ -150,6 +150,12 @@ export class TwitterHandler extends ContentHandler {
throw new Error('could not find tweet id in url')
}
let tweet = await getTweetById(tweetId)
const conversationId = tweet.data.conversation_id
if (conversationId !== tweetId) {
// this is a reply, so we need to get the referenced tweet
tweet = await getTweetById(conversationId)
}
const tweetData = tweet.data
const authorId = tweetData.author_id
const author = tweet.includes.users.filter((u) => (u.id = authorId))[0]
@ -157,18 +163,10 @@ export class TwitterHandler extends ContentHandler {
const title = _.escape(titleForAuthor(author))
const authorImage = author.profile_image_url.replace('_normal', '_400x400')
const description = _.escape(tweetData.text)
const converstationId = tweetData.conversation_id
if (converstationId !== tweetId) {
// this is a reply, so we need to get the referenced tweet
tweet = await getTweetById(converstationId)
}
const tweets = [tweet]
// we want to get the full thread
const thread = await getTweetThread(
tweetData.conversation_id,
author.username
)
const thread = await getTweetThread(conversationId, author.username)
if (thread.meta.result_count > 0) {
// tweets are in reverse chronological order in the thread
for (const t of thread.data.reverse()) {