mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
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:
commit
9b64299c6b
2 changed files with 9 additions and 27 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
@ -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()) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue