Improve timeline support, "no more tweets" message
This commit is contained in:
parent
c4d648e952
commit
ac8d0e2052
4 changed files with 38 additions and 13 deletions
|
@ -575,7 +575,14 @@ nav {
|
||||||
.timeline-protected-header {
|
.timeline-protected-header {
|
||||||
color: #d0564c;
|
color: #d0564c;
|
||||||
font-size: 21px;
|
font-size: 21px;
|
||||||
font-weight: bold;
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-end {
|
||||||
|
text-align: center;
|
||||||
|
font-size: 16px;
|
||||||
|
color: #ff6c60;
|
||||||
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
.media-gif {
|
.media-gif {
|
||||||
|
|
17
src/api.nim
17
src/api.nim
|
@ -150,7 +150,7 @@ proc getProfile*(username: string): Future[Profile] {.async.} =
|
||||||
|
|
||||||
result = parsePopupProfile(html)
|
result = parsePopupProfile(html)
|
||||||
|
|
||||||
proc getTimeline*(username: string; after=""): Future[Tweets] {.async.} =
|
proc getTimeline*(username: string; after=""): Future[Timeline] {.async.} =
|
||||||
let headers = newHttpHeaders({
|
let headers = newHttpHeaders({
|
||||||
"Accept": "application/json, text/javascript, */*; q=0.01",
|
"Accept": "application/json, text/javascript, */*; q=0.01",
|
||||||
"Referer": $(base / username),
|
"Referer": $(base / username),
|
||||||
|
@ -164,10 +164,19 @@ proc getTimeline*(username: string; after=""): Future[Tweets] {.async.} =
|
||||||
if after.len > 0:
|
if after.len > 0:
|
||||||
url &= "&max_position=" & after
|
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)
|
result = Timeline(
|
||||||
await getVideos(result)
|
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.} =
|
proc getTweet*(id: string): Future[Conversation] {.async.} =
|
||||||
let headers = newHttpHeaders({
|
let headers = newHttpHeaders({
|
||||||
|
|
|
@ -78,5 +78,11 @@ type
|
||||||
after*: Tweets
|
after*: Tweets
|
||||||
replies*: seq[Tweets]
|
replies*: seq[Tweets]
|
||||||
|
|
||||||
|
Timeline* = ref object
|
||||||
|
tweets*: Tweets
|
||||||
|
minId*: string
|
||||||
|
maxId*: string
|
||||||
|
hasMore*: bool
|
||||||
|
|
||||||
proc contains*(thread: Tweets; tweet: Tweet): bool =
|
proc contains*(thread: Tweets; tweet: Tweet): bool =
|
||||||
thread.anyIt(it.id == tweet.id)
|
thread.anyIt(it.id == tweet.id)
|
||||||
|
|
|
@ -52,7 +52,7 @@
|
||||||
#end if
|
#end if
|
||||||
#end proc
|
#end proc
|
||||||
#
|
#
|
||||||
#proc renderTimeline*(tweets: Tweets; profile: Profile; beginning: bool): string =
|
#proc renderTimeline*(timeline: Timeline; profile: Profile; beginning: bool): string =
|
||||||
<div id="tweets">
|
<div id="tweets">
|
||||||
#if profile.protected:
|
#if profile.protected:
|
||||||
<div class="timeline-protected">
|
<div class="timeline-protected">
|
||||||
|
@ -66,19 +66,22 @@
|
||||||
</div>
|
</div>
|
||||||
#end if
|
#end if
|
||||||
#var retweets: Tweets
|
#var retweets: Tweets
|
||||||
#for tweet in tweets:
|
#for tweet in timeline.tweets:
|
||||||
#if tweet in retweets: continue
|
#if tweet in retweets: continue
|
||||||
#elif tweet.retweetBy.isSome: retweets.add tweet
|
#elif tweet.retweetBy.isSome: retweets.add tweet
|
||||||
#end if
|
#end if
|
||||||
${renderTweet(tweet, "timeline-tweet")}
|
${renderTweet(tweet, "timeline-tweet")}
|
||||||
#end for
|
#end for
|
||||||
#if tweets.len > 0:
|
#if timeline.hasMore:
|
||||||
<div class="show-more">
|
<div class="show-more">
|
||||||
#let retweet = tweets[^1].retweetId.get("")
|
<a href="/${profile.username}?after=${timeline.minId}">Load older tweets</a>
|
||||||
#let id = if retweet.len > 0: retweet else: tweets[^1].id
|
|
||||||
<a href="/${profile.username}?after=${$id}">Load older tweets</a>
|
|
||||||
</div>
|
</div>
|
||||||
#else:
|
#else:
|
||||||
|
<div class="timeline-protected">
|
||||||
|
<h2 class="timeline-end" style="text-align: center;">No more tweets.</h2>
|
||||||
|
</div>
|
||||||
|
#end if
|
||||||
|
#if timeline.tweets.len == 0:
|
||||||
<div class="timeline-protected">
|
<div class="timeline-protected">
|
||||||
<h2 class="timeline-protected-header" style="text-align: center;">No tweets found.</h2>
|
<h2 class="timeline-protected-header" style="text-align: center;">No tweets found.</h2>
|
||||||
</div>
|
</div>
|
||||||
|
@ -86,7 +89,7 @@
|
||||||
</div>
|
</div>
|
||||||
#end proc
|
#end proc
|
||||||
#
|
#
|
||||||
#proc renderProfile*(profile: Profile; tweets: Tweets; beginning: bool): string =
|
#proc renderProfile*(profile: Profile; timeline: Timeline; beginning: bool): string =
|
||||||
<div class="profile-tabs">
|
<div class="profile-tabs">
|
||||||
<div class="profile-banner">
|
<div class="profile-banner">
|
||||||
${renderBanner(profile)}
|
${renderBanner(profile)}
|
||||||
|
@ -95,7 +98,7 @@
|
||||||
${renderProfileCard(profile)}
|
${renderProfileCard(profile)}
|
||||||
</div>
|
</div>
|
||||||
<div class="timeline-tab">
|
<div class="timeline-tab">
|
||||||
${renderTimeline(tweets, profile, beginning)}
|
${renderTimeline(timeline, profile, beginning)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
#end proc
|
#end proc
|
||||||
|
|
Loading…
Reference in a new issue