Merge pull request #1293 from omnivore-app/fix/twitter-thread

If the saved tweet is a reply, we need to get the referenced tweet
This commit is contained in:
Hongbo Wu 2022-10-10 15:34:53 +08:00 committed by GitHub
commit 9b64299c6b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 27 deletions

View file

@ -1,21 +0,0 @@
export class GolangHandler {
name = 'golangweekly'
// eslint-disable-next-line @typescript-eslint/no-unused-vars
shouldPrehandle = (url: URL, _dom: Document): boolean => {
const host = this.name + '.com'
// check if url ends with golangweekly.com
return url.hostname.endsWith(host)
}
prehandle = (url: URL, dom: Document): Promise<Document> => {
const body = dom.querySelector('body')
// this removes the "Subscribe" button
body?.querySelector('.el-splitbar')?.remove()
// this removes the title
body?.querySelector('.el-masthead')?.remove()
return Promise.resolve(dom)
}
}

View file

@ -149,7 +149,13 @@ export class TwitterHandler extends ContentHandler {
if (!tweetId) {
throw new Error('could not find tweet id in url')
}
const tweet = await getTweetById(tweetId)
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]
@ -159,11 +165,8 @@ export class TwitterHandler extends ContentHandler {
const description = _.escape(tweetData.text)
const tweets = [tweet]
// check if tweet is a thread
const thread = await getTweetThread(
tweetData.conversation_id,
author.username
)
// we want to get the full thread
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()) {