Fix parsing censored tweets

This commit is contained in:
Zed 2020-11-07 22:48:49 +01:00
parent 509e1dc5e8
commit 2d7e12fcb8
2 changed files with 17 additions and 5 deletions

View File

@ -328,7 +328,7 @@ proc parseThread(js: JsonNode; global: GlobalObjects): tuple[thread: Chain, self
else:
result.thread.more = -1
else:
var tweet = finalizeTweet(global, entry.getId)
var tweet = finalizeTweet(global, t.getEntryId)
if not tweet.available:
tweet.tombstone = getTombstone(content{"tombstone"})
result.thread.content.add tweet
@ -343,8 +343,8 @@ proc parseConversation*(js: JsonNode; tweetId: string): Conversation =
for e in instructions[0]{"addEntries", "entries"}:
let entry = e{"entryId"}.getStr
if "tweet" in entry:
let tweet = finalizeTweet(global, entry.getId)
if "tweet" in entry or "tombstone" in entry:
let tweet = finalizeTweet(global, e.getEntryId)
if $tweet.id != tweetId:
result.before.content.add tweet
else:
@ -408,8 +408,8 @@ proc parseTimeline*(js: JsonNode; after=""): Timeline =
for e in instructions[0]{"addEntries", "entries"}:
let entry = e{"entryId"}.getStr
if "tweet" in entry or "sq-I-t" in entry:
let tweet = finalizeTweet(global, entry.getId)
if "tweet" in entry or "sq-I-t" in entry or "tombstone" in entry:
let tweet = finalizeTweet(global, e.getEntryId)
if not tweet.available: continue
result.content.add tweet
elif "cursor-top" in entry:

View File

@ -55,6 +55,18 @@ proc getId*(js: JsonNode): int64 {.inline.} =
of JInt: return js.getBiggestInt()
else: return 0
proc getEntryId*(js: JsonNode): string {.inline.} =
let entry = js{"entryId"}.getStr
if entry.len == 0: return
if "tweet" in entry:
return entry.getId
elif "tombstone" in entry:
return js{"content", "item", "content", "tombstone", "tweet", "id"}.getStr
else:
echo "unknown entry: ", entry
return
template getStrVal*(js: JsonNode; default=""): string =
js{"string_value"}.getStr(default)