Fix crash on unavailable tweets

This commit is contained in:
Zed 2023-02-25 18:25:02 +01:00
parent 85f14c9a64
commit 2751504d2f
3 changed files with 6 additions and 3 deletions

View file

@ -372,7 +372,7 @@ proc parsePhotoRail*(js: JsonNode): PhotoRail =
result.add GalleryPhoto(url: url, tweetId: $t.id) result.add GalleryPhoto(url: url, tweetId: $t.id)
proc parseGraphTweet(js: JsonNode): Tweet = proc parseGraphTweet(js: JsonNode): Tweet =
if js.kind == JNull: if js.kind == JNull or js{"__typename"}.getStr == "TweetUnavailable":
return Tweet(available: false) return Tweet(available: false)
var jsCard = copy(js{"card", "legacy"}) var jsCard = copy(js{"card", "legacy"})
@ -416,6 +416,9 @@ proc parseGraphConversation*(js: JsonNode; tweetId: string): Conversation =
if entryId.startsWith("tweet"): if entryId.startsWith("tweet"):
let tweet = parseGraphTweet(e{"content", "itemContent", "tweet_results", "result"}) let tweet = parseGraphTweet(e{"content", "itemContent", "tweet_results", "result"})
if not tweet.available:
tweet.id = parseBiggestInt(entryId.getId())
if $tweet.id == tweetId: if $tweet.id == tweetId:
result.tweet = tweet result.tweet = tweet
else: else:

View file

@ -177,7 +177,7 @@ type
available*: bool available*: bool
tombstone*: string tombstone*: string
location*: string location*: string
## Unused, needed for backwards compat # Unused, needed for backwards compat
source*: string source*: string
stats*: TweetStats stats*: TweetStats
retweet*: Option[Tweet] retweet*: Option[Tweet]

View file

@ -42,7 +42,7 @@ no_thumb = [
['nim_lang/status/1082989146040340480', ['nim_lang/status/1082989146040340480',
'Nim in 2018: A short recap', 'Nim in 2018: A short recap',
'Posted in r/programming by u/miran1', '36 votes and 46 comments so far on Reddit',
'reddit.com'] 'reddit.com']
] ]