@@ -352,18 +352,23 @@ proc parseGraphTweetResult*(js: JsonNode): Tweet =
352352 with tweet, js{" data" , " tweet_result" , " result" }:
353353 result = parseGraphTweet (tweet, false )
354354
355- proc parseGraphConversation * (js: JsonNode ; tweetId: string ): Conversation =
355+ proc parseGraphConversation * (js: JsonNode ; tweetId: string ; v2 = true ): Conversation =
356356 result = Conversation (replies: Result [Chain ](beginning: true ))
357357
358- let instructions = ? js{" data" , " threaded_conversation_with_injections_v2" , " instructions" }
358+ let
359+ rootKey = if v2: " timeline_response" else : " threaded_conversation_with_injections_v2"
360+ contentKey = if v2: " content" else : " itemContent"
361+ resultKey = if v2: " tweetResult" else : " tweet_results"
362+
363+ let instructions = ? js{" data" , rootKey, " instructions" }
359364 if instructions.len == 0 :
360365 return
361366
362367 for e in instructions[0 ]{" entries" }:
363368 let entryId = e{" entryId" }.getStr
364369 if entryId.startsWith (" tweet" ):
365- with tweetResult, e{" content" , " itemContent " , " tweet_results " , " result" }:
366- let tweet = parseGraphTweet (tweetResult, true )
370+ with tweetResult, e{" content" , contentKey, resultKey , " result" }:
371+ let tweet = parseGraphTweet (tweetResult, not v2 )
367372
368373 if not tweet.available:
369374 tweet.id = parseBiggestInt (entryId.getId ())
@@ -372,26 +377,26 @@ proc parseGraphConversation*(js: JsonNode; tweetId: string): Conversation =
372377 result .tweet = tweet
373378 else :
374379 result .before.content.add tweet
380+ elif entryId.startsWith (" conversationthread" ):
381+ let (thread, self) = parseGraphThread (e)
382+ if self:
383+ result .after = thread
384+ else :
385+ result .replies.content.add thread
375386 elif entryId.startsWith (" tombstone" ):
376387 let id = entryId.getId ()
377388 let tweet = Tweet (
378389 id: parseBiggestInt (id),
379390 available: false ,
380- text: e{" content" , " itemContent " , " tombstoneInfo" , " richText" }.getTombstone
391+ text: e{" content" , contentKey , " tombstoneInfo" , " richText" }.getTombstone
381392 )
382393
383394 if id == tweetId:
384395 result .tweet = tweet
385396 else :
386397 result .before.content.add tweet
387- elif entryId.startsWith (" conversationthread" ):
388- let (thread, self) = parseGraphThread (e)
389- if self:
390- result .after = thread
391- else :
392- result .replies.content.add thread
393398 elif entryId.startsWith (" cursor-bottom" ):
394- result .replies.bottom = e{" content" , " itemContent " , " value" }.getStr
399+ result .replies.bottom = e{" content" , contentKey , " value" }.getStr
395400
396401proc parseGraphTimeline * (js: JsonNode ; root: string ; after= " " ): Profile =
397402 result = Profile (tweets: Timeline (beginning: after.len == 0 ))
0 commit comments