Handle withheld tweets (#429)
* Handle withheld tweets * Fix format of parser.nim
This commit is contained in:
parent
739eb12bed
commit
cf47c1b8ad
|
@ -17,7 +17,7 @@ requires "sass#e683aa1"
|
||||||
requires "regex#2e32fdc"
|
requires "regex#2e32fdc"
|
||||||
requires "nimcrypto >= 0.4.11"
|
requires "nimcrypto >= 0.4.11"
|
||||||
requires "markdown#abdbe5e"
|
requires "markdown#abdbe5e"
|
||||||
requires "packedjson#7198cc8"
|
requires "packedjson#d11d167"
|
||||||
requires "supersnappy#1.1.5"
|
requires "supersnappy#1.1.5"
|
||||||
requires "redpool#f880f49"
|
requires "redpool#f880f49"
|
||||||
requires "https://github.com/zedeus/redis#94bcbf1"
|
requires "https://github.com/zedeus/redis#94bcbf1"
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import strutils, options, tables, times, math
|
import strutils, options, tables, times, math
|
||||||
import packedjson
|
import packedjson
|
||||||
|
import packedjson / deserialiser
|
||||||
import types, parserutils, utils
|
import types, parserutils, utils
|
||||||
|
|
||||||
proc parseProfile(js: JsonNode; id=""): Profile =
|
proc parseProfile(js: JsonNode; id=""): Profile =
|
||||||
|
@ -268,6 +269,21 @@ proc parseTweet(js: JsonNode): Tweet =
|
||||||
result.gif = some(parseGif(m))
|
result.gif = some(parseGif(m))
|
||||||
else: discard
|
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 =
|
proc finalizeTweet(global: GlobalObjects; id: string): Tweet =
|
||||||
let intId = if id.len > 0: parseBiggestInt(id) else: 0
|
let intId = if id.len > 0: parseBiggestInt(id) else: 0
|
||||||
result = global.tweets.getOrDefault(id, Tweet(id: intId))
|
result = global.tweets.getOrDefault(id, Tweet(id: intId))
|
||||||
|
|
|
@ -158,4 +158,8 @@
|
||||||
padding: .75em;
|
padding: .75em;
|
||||||
display: flex;
|
display: flex;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
||||||
|
&.unavailable {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,6 +188,7 @@
|
||||||
height: 100%;
|
height: 100%;
|
||||||
padding: 12px;
|
padding: 12px;
|
||||||
border: solid 1px var(--dark_grey);
|
border: solid 1px var(--dark_grey);
|
||||||
|
box-sizing: border-box;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
background-color: var(--bg_color);
|
background-color: var(--bg_color);
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,6 +226,8 @@ proc renderQuote(quote: Tweet; prefs: Prefs; path: string): VNode =
|
||||||
tdiv(class="unavailable-quote"):
|
tdiv(class="unavailable-quote"):
|
||||||
if quote.tombstone.len > 0:
|
if quote.tombstone.len > 0:
|
||||||
text quote.tombstone
|
text quote.tombstone
|
||||||
|
elif quote.text.len > 0:
|
||||||
|
text quote.text
|
||||||
else:
|
else:
|
||||||
text "This tweet is unavailable"
|
text "This tweet is unavailable"
|
||||||
|
|
||||||
|
@ -278,9 +280,14 @@ proc renderTweet*(tweet: Tweet; prefs: Prefs; path: string; class=""; index=0;
|
||||||
tdiv(class="unavailable-box"):
|
tdiv(class="unavailable-box"):
|
||||||
if tweet.tombstone.len > 0:
|
if tweet.tombstone.len > 0:
|
||||||
text tweet.tombstone
|
text tweet.tombstone
|
||||||
|
elif tweet.text.len > 0:
|
||||||
|
text tweet.text
|
||||||
else:
|
else:
|
||||||
text "This tweet is unavailable"
|
text "This tweet is unavailable"
|
||||||
|
|
||||||
|
if tweet.quote.isSome:
|
||||||
|
renderQuote(tweet.quote.get(), prefs, path)
|
||||||
|
|
||||||
let fullTweet = tweet
|
let fullTweet = tweet
|
||||||
var retweet: string
|
var retweet: string
|
||||||
var tweet = fullTweet
|
var tweet = fullTweet
|
||||||
|
|
Loading…
Reference in New Issue