From cf47c1b8ad3affa43881ea661c8a5a11d206dfa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor?= Date: Sat, 21 Aug 2021 12:13:38 -0300 Subject: [PATCH] Handle withheld tweets (#429) * Handle withheld tweets * Fix format of parser.nim --- nitter.nimble | 2 +- src/parser.nim | 16 ++++++++++++++++ src/sass/timeline.scss | 4 ++++ src/sass/tweet/_base.scss | 1 + src/views/tweet.nim | 7 +++++++ 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/nitter.nimble b/nitter.nimble index 1fc9c6e..25e38ec 100644 --- a/nitter.nimble +++ b/nitter.nimble @@ -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" diff --git a/src/parser.nim b/src/parser.nim index 9f44b14..fffb3c9 100644 --- a/src/parser.nim +++ b/src/parser.nim @@ -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)) diff --git a/src/sass/timeline.scss b/src/sass/timeline.scss index db19bed..8ffbf79 100644 --- a/src/sass/timeline.scss +++ b/src/sass/timeline.scss @@ -158,4 +158,8 @@ padding: .75em; display: flex; position: relative; + + &.unavailable { + flex-direction: column; + } } diff --git a/src/sass/tweet/_base.scss b/src/sass/tweet/_base.scss index 9ac86e9..e6069b3 100644 --- a/src/sass/tweet/_base.scss +++ b/src/sass/tweet/_base.scss @@ -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); } diff --git a/src/views/tweet.nim b/src/views/tweet.nim index 4efbe67..a16fdd5 100644 --- a/src/views/tweet.nim +++ b/src/views/tweet.nim @@ -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