diff --git a/public/style.css b/public/style.css index cc61dae..c59cff4 100644 --- a/public/style.css +++ b/public/style.css @@ -575,7 +575,14 @@ nav { .timeline-protected-header { color: #d0564c; font-size: 21px; - font-weight: bold; + font-weight: 600; +} + +.timeline-end { + text-align: center; + font-size: 16px; + color: #ff6c60; + font-weight: 600; } .media-gif { diff --git a/src/api.nim b/src/api.nim index 523f9e7..31af03d 100644 --- a/src/api.nim +++ b/src/api.nim @@ -150,7 +150,7 @@ proc getProfile*(username: string): Future[Profile] {.async.} = result = parsePopupProfile(html) -proc getTimeline*(username: string; after=""): Future[Tweets] {.async.} = +proc getTimeline*(username: string; after=""): Future[Timeline] {.async.} = let headers = newHttpHeaders({ "Accept": "application/json, text/javascript, */*; q=0.01", "Referer": $(base / username), @@ -164,10 +164,19 @@ proc getTimeline*(username: string; after=""): Future[Tweets] {.async.} = if after.len > 0: url &= "&max_position=" & after - let html = await fetchHtml(base / url, headers, jsonKey="items_html") + let json = await fetchJson(base / url, headers) + let html = parseHtml(json["items_html"].to(string)) - result = parseTweets(html) - await getVideos(result) + result = Timeline( + tweets: parseTweets(html), + minId: json["min_position"].to(string), + hasMore: json["has_more_items"].to(bool), + ) + + if json.hasKey("max_position"): + result.maxId = json["max_position"].to(string) + + await getVideos(result.tweets) proc getTweet*(id: string): Future[Conversation] {.async.} = let headers = newHttpHeaders({ diff --git a/src/types.nim b/src/types.nim index 58e3f85..9ad1f95 100644 --- a/src/types.nim +++ b/src/types.nim @@ -78,5 +78,11 @@ type after*: Tweets replies*: seq[Tweets] + Timeline* = ref object + tweets*: Tweets + minId*: string + maxId*: string + hasMore*: bool + proc contains*(thread: Tweets; tweet: Tweet): bool = thread.anyIt(it.id == tweet.id) diff --git a/src/views/user.nimf b/src/views/user.nimf index 56b4c33..efea08a 100644 --- a/src/views/user.nimf +++ b/src/views/user.nimf @@ -52,7 +52,7 @@ #end if #end proc # -#proc renderTimeline*(tweets: Tweets; profile: Profile; beginning: bool): string = +#proc renderTimeline*(timeline: Timeline; profile: Profile; beginning: bool): string =
#if profile.protected:
@@ -66,19 +66,22 @@
#end if #var retweets: Tweets - #for tweet in tweets: + #for tweet in timeline.tweets: #if tweet in retweets: continue #elif tweet.retweetBy.isSome: retweets.add tweet #end if ${renderTweet(tweet, "timeline-tweet")} #end for - #if tweets.len > 0: + #if timeline.hasMore:
- #let retweet = tweets[^1].retweetId.get("") - #let id = if retweet.len > 0: retweet else: tweets[^1].id - Load older tweets + Load older tweets
#else: +
+

No more tweets.

+
+ #end if + #if timeline.tweets.len == 0:

No tweets found.

@@ -86,7 +89,7 @@
#end proc # -#proc renderProfile*(profile: Profile; tweets: Tweets; beginning: bool): string = +#proc renderProfile*(profile: Profile; timeline: Timeline; beginning: bool): string =
${renderBanner(profile)} @@ -95,7 +98,7 @@ ${renderProfileCard(profile)}
- ${renderTimeline(tweets, profile, beginning)} + ${renderTimeline(timeline, profile, beginning)}
#end proc