2019-10-26 13:34:30 +00:00
|
|
|
import strutils, strformat, sequtils, algorithm, times, uri, options
|
2019-07-10 22:42:31 +00:00
|
|
|
import karax/[karaxdsl, vdom, vstyles]
|
|
|
|
|
2019-09-13 17:57:27 +00:00
|
|
|
import ".."/[types, query, formatters]
|
2019-07-10 22:42:31 +00:00
|
|
|
import tweet, renderutils
|
|
|
|
|
2019-09-19 00:23:22 +00:00
|
|
|
proc getQuery(query: Query): string =
|
2019-09-20 20:56:27 +00:00
|
|
|
if query.kind != posts:
|
2019-09-19 00:23:22 +00:00
|
|
|
result = genQueryUrl(query)
|
2019-09-20 20:56:27 +00:00
|
|
|
if result.len > 0:
|
|
|
|
result &= "&"
|
2019-07-10 22:42:31 +00:00
|
|
|
|
2019-09-24 13:39:04 +00:00
|
|
|
proc renderNewer*(query: Query; path: string): VNode =
|
2019-09-20 23:11:03 +00:00
|
|
|
let q = genQueryUrl(query)
|
|
|
|
let url = if q.len > 0: "?" & q else: ""
|
2019-09-13 17:57:27 +00:00
|
|
|
buildHtml(tdiv(class="timeline-item show-more")):
|
2019-09-20 23:11:03 +00:00
|
|
|
a(href=(path & url)):
|
2019-09-13 17:57:27 +00:00
|
|
|
text "Load newest"
|
2019-07-10 22:42:31 +00:00
|
|
|
|
2019-10-22 07:18:18 +00:00
|
|
|
proc renderMore*(query: Query; minId: string; focus=""): VNode =
|
2019-07-10 22:42:31 +00:00
|
|
|
buildHtml(tdiv(class="show-more")):
|
2019-10-22 07:18:18 +00:00
|
|
|
a(href=(&"?{getQuery(query)}max_position={minId}{focus}")):
|
2019-09-20 20:56:27 +00:00
|
|
|
text "Load more"
|
2019-07-10 22:42:31 +00:00
|
|
|
|
|
|
|
proc renderNoMore(): VNode =
|
|
|
|
buildHtml(tdiv(class="timeline-footer")):
|
2019-09-13 08:44:21 +00:00
|
|
|
h2(class="timeline-end"):
|
2019-09-13 17:57:27 +00:00
|
|
|
text "No more items"
|
2019-07-10 22:42:31 +00:00
|
|
|
|
|
|
|
proc renderNoneFound(): VNode =
|
|
|
|
buildHtml(tdiv(class="timeline-header")):
|
2019-09-13 08:44:21 +00:00
|
|
|
h2(class="timeline-none"):
|
2019-09-13 17:57:27 +00:00
|
|
|
text "No items found"
|
2019-07-10 22:42:31 +00:00
|
|
|
|
2019-10-13 18:17:12 +00:00
|
|
|
proc renderToTop(): VNode =
|
|
|
|
buildHtml(tdiv(class="top-ref")):
|
|
|
|
icon "down", href="#"
|
|
|
|
|
2019-09-05 20:40:36 +00:00
|
|
|
proc renderThread(thread: seq[Tweet]; prefs: Prefs; path: string): VNode =
|
2019-09-13 17:57:27 +00:00
|
|
|
buildHtml(tdiv(class="thread-line")):
|
2019-10-23 07:47:15 +00:00
|
|
|
let sortedThread = thread.sortedByIt(it.id)
|
|
|
|
for i, tweet in sortedThread:
|
|
|
|
let show = i == thread.high and sortedThread[0].id != tweet.threadId
|
2019-11-08 21:53:11 +00:00
|
|
|
let header = if tweet.pinned or tweet.retweet.isSome: "with-header " else: ""
|
|
|
|
renderTweet(tweet, prefs, path, class=(header & "thread"),
|
2019-09-19 01:51:15 +00:00
|
|
|
index=i, total=thread.high, showThread=show)
|
2019-07-10 22:42:31 +00:00
|
|
|
|
2019-12-09 23:39:12 +00:00
|
|
|
proc threadFilter(it: Tweet; thread: int64): bool =
|
2019-10-10 16:22:14 +00:00
|
|
|
it.retweet.isNone and it.reply.len == 0 and it.threadId == thread
|
2019-07-10 22:42:31 +00:00
|
|
|
|
2019-09-13 20:24:58 +00:00
|
|
|
proc renderUser(user: Profile; prefs: Prefs): VNode =
|
|
|
|
buildHtml(tdiv(class="timeline-item")):
|
2019-09-20 00:49:54 +00:00
|
|
|
a(class="tweet-link", href=("/" & user.username))
|
2019-09-13 20:24:58 +00:00
|
|
|
tdiv(class="tweet-body profile-result"):
|
|
|
|
tdiv(class="tweet-header"):
|
|
|
|
a(class="tweet-avatar", href=("/" & user.username)):
|
|
|
|
genImg(user.getUserpic("_bigger"), class="avatar")
|
|
|
|
|
|
|
|
tdiv(class="tweet-name-row"):
|
|
|
|
tdiv(class="fullname-and-username"):
|
|
|
|
linkUser(user, class="fullname")
|
|
|
|
linkUser(user, class="username")
|
|
|
|
|
2019-10-17 22:54:22 +00:00
|
|
|
tdiv(class="tweet-content media-body", dir="auto"):
|
2019-10-09 14:06:51 +00:00
|
|
|
verbatim replaceUrl(user.bio, prefs)
|
2019-09-13 20:24:58 +00:00
|
|
|
|
2019-09-20 20:56:27 +00:00
|
|
|
proc renderTimelineUsers*(results: Result[Profile]; prefs: Prefs; path=""): VNode =
|
2019-09-13 20:24:58 +00:00
|
|
|
buildHtml(tdiv(class="timeline")):
|
|
|
|
if not results.beginning:
|
2019-09-20 20:56:27 +00:00
|
|
|
renderNewer(results.query, path)
|
2019-09-13 20:24:58 +00:00
|
|
|
|
|
|
|
if results.content.len > 0:
|
|
|
|
for user in results.content:
|
|
|
|
renderUser(user, prefs)
|
2019-09-20 23:08:30 +00:00
|
|
|
if results.minId != "0":
|
|
|
|
renderMore(results.query, results.minId)
|
2019-10-13 18:17:12 +00:00
|
|
|
renderToTop()
|
2019-09-13 20:24:58 +00:00
|
|
|
elif results.beginning:
|
|
|
|
renderNoneFound()
|
|
|
|
else:
|
|
|
|
renderNoMore()
|
2019-09-13 17:57:27 +00:00
|
|
|
|
|
|
|
proc renderTimelineTweets*(results: Result[Tweet]; prefs: Prefs; path: string): VNode =
|
|
|
|
buildHtml(tdiv(class="timeline")):
|
|
|
|
if not results.beginning:
|
2019-09-20 20:56:27 +00:00
|
|
|
renderNewer(results.query, parseUri(path).path)
|
2019-09-13 17:57:27 +00:00
|
|
|
|
|
|
|
if results.content.len == 0:
|
2019-07-10 22:42:31 +00:00
|
|
|
renderNoneFound()
|
|
|
|
else:
|
2019-12-09 23:39:12 +00:00
|
|
|
var threads: seq[int64]
|
|
|
|
var retweets: seq[int64]
|
2019-09-13 17:57:27 +00:00
|
|
|
for tweet in results.content:
|
2019-09-19 23:17:25 +00:00
|
|
|
if tweet.threadId in threads or tweet.id in retweets: continue
|
2019-10-29 17:32:35 +00:00
|
|
|
if tweet.pinned and prefs.hidePins: continue
|
2019-09-13 17:57:27 +00:00
|
|
|
let thread = results.content.filterIt(threadFilter(it, tweet.threadId))
|
|
|
|
if thread.len < 2:
|
2019-09-19 23:17:25 +00:00
|
|
|
if tweet.retweet.isSome:
|
|
|
|
retweets &= tweet.id
|
2019-09-19 01:51:15 +00:00
|
|
|
renderTweet(tweet, prefs, path, showThread=tweet.hasThread)
|
2019-09-13 17:57:27 +00:00
|
|
|
else:
|
|
|
|
renderThread(thread, prefs, path)
|
|
|
|
threads &= tweet.threadId
|
|
|
|
|
2019-09-19 00:23:22 +00:00
|
|
|
if results.hasMore or results.query.kind != posts:
|
2019-09-20 20:56:27 +00:00
|
|
|
renderMore(results.query, results.minId)
|
2019-07-10 22:42:31 +00:00
|
|
|
else:
|
|
|
|
renderNoMore()
|
2019-10-13 18:17:12 +00:00
|
|
|
renderToTop()
|