Use old api to optimize photo rails

This commit is contained in:
Zed
2020-06-17 00:20:34 +02:00
parent 7e40af5611
commit 77da2e32c6
7 changed files with 37 additions and 40 deletions

View File

@@ -412,24 +412,14 @@ proc parseTimeline*(js: JsonNode; after=""): Timeline =
result.bottom = e.getCursor
proc parsePhotoRail*(js: JsonNode): PhotoRail =
let
tweets = ? js{"globalObjects", "tweets"}
instructions = ? js{"timeline", "instructions"}
for tweet in js:
let
t = parseTweet(tweet)
url = if t.photos.len > 0: t.photos[0]
elif t.video.isSome: get(t.video).thumb
elif t.gif.isSome: get(t.gif).thumb
elif t.card.isSome: get(t.card).image
else: ""
if instructions.len == 0 or tweets.len == 0: return
for e in instructions[0]{"addEntries", "entries"}:
if result.len == 16: break
let entry = e{"entryId"}.getStr
if "tweet" in entry:
let id = entry.getId
if id notin tweets: continue
let tweet = parseTweet(tweets{id})
var url = if tweet.photos.len > 0: tweet.photos[0]
elif tweet.video.isSome: get(tweet.video).thumb
elif tweet.gif.isSome: get(tweet.gif).thumb
elif tweet.card.isSome: get(tweet.card).image
else: ""
if url.len == 0: continue
result.add GalleryPhoto(url: url, tweetId: $tweet.id)
if url.len == 0: continue
result.add GalleryPhoto(url: url, tweetId: $t.id)