Handle withheld tweets (#429)

* Handle withheld tweets

* Fix format of parser.nim
This commit is contained in:
Vítor 2021-08-21 12:13:38 -03:00 committed by GitHub
parent 739eb12bed
commit cf47c1b8ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 1 deletions

View File

@ -17,7 +17,7 @@ requires "sass#e683aa1"
requires "regex#2e32fdc"
requires "nimcrypto >= 0.4.11"
requires "markdown#abdbe5e"
requires "packedjson#7198cc8"
requires "packedjson#d11d167"
requires "supersnappy#1.1.5"
requires "redpool#f880f49"
requires "https://github.com/zedeus/redis#94bcbf1"

View File

@ -1,5 +1,6 @@
import strutils, options, tables, times, math
import packedjson
import packedjson / deserialiser
import types, parserutils, utils
proc parseProfile(js: JsonNode; id=""): Profile =
@ -268,6 +269,21 @@ proc parseTweet(js: JsonNode): Tweet =
result.gif = some(parseGif(m))
else: discard
let withheldInCountries = (
if js{"withheld_in_countries"}.kind == JArray:
js{"withheld_in_countries"}.to(seq[string])
else:
newSeq[string]()
)
if js{"withheld_copyright"}.getBool or
# XX - Content is withheld in all countries
"XX" in withheldInCountries or
# XY - Content is withheld due to a DMCA request.
"XY" in withheldInCountries or
(withheldInCountries.len > 0 and "withheld" in result.text):
result.available = false
proc finalizeTweet(global: GlobalObjects; id: string): Tweet =
let intId = if id.len > 0: parseBiggestInt(id) else: 0
result = global.tweets.getOrDefault(id, Tweet(id: intId))

View File

@ -158,4 +158,8 @@
padding: .75em;
display: flex;
position: relative;
&.unavailable {
flex-direction: column;
}
}

View File

@ -188,6 +188,7 @@
height: 100%;
padding: 12px;
border: solid 1px var(--dark_grey);
box-sizing: border-box;
border-radius: 10px;
background-color: var(--bg_color);
}

View File

@ -226,6 +226,8 @@ proc renderQuote(quote: Tweet; prefs: Prefs; path: string): VNode =
tdiv(class="unavailable-quote"):
if quote.tombstone.len > 0:
text quote.tombstone
elif quote.text.len > 0:
text quote.text
else:
text "This tweet is unavailable"
@ -278,9 +280,14 @@ proc renderTweet*(tweet: Tweet; prefs: Prefs; path: string; class=""; index=0;
tdiv(class="unavailable-box"):
if tweet.tombstone.len > 0:
text tweet.tombstone
elif tweet.text.len > 0:
text tweet.text
else:
text "This tweet is unavailable"
if tweet.quote.isSome:
renderQuote(tweet.quote.get(), prefs, path)
let fullTweet = tweet
var retweet: string
var tweet = fullTweet