2019-07-11 00:42:31 +02:00
|
|
|
import karax/[karaxdsl, vdom]
|
|
|
|
|
2019-09-24 15:39:04 +02:00
|
|
|
import ".."/[types, formatters]
|
|
|
|
import tweet, timeline
|
2019-07-11 00:42:31 +02:00
|
|
|
|
2019-10-08 20:47:45 +02:00
|
|
|
proc renderMoreReplies(thread: Chain): VNode =
|
2019-08-23 01:20:00 +02:00
|
|
|
let num = if thread.more != -1: $thread.more & " " else: ""
|
|
|
|
let reply = if thread.more == 1: "reply" else: "replies"
|
2019-09-24 16:34:50 +02:00
|
|
|
let link = getLink(thread.content[^1])
|
2019-09-13 19:57:27 +02:00
|
|
|
buildHtml(tdiv(class="timeline-item more-replies")):
|
2019-09-24 16:01:09 +02:00
|
|
|
if link.len > 0:
|
2019-09-24 16:34:50 +02:00
|
|
|
a(class="more-replies-text", href=link):
|
2019-09-24 16:01:09 +02:00
|
|
|
text $num & "more " & reply
|
|
|
|
else:
|
|
|
|
a(class="more-replies-text"):
|
|
|
|
text $num & "more " & reply
|
2019-08-23 01:20:00 +02:00
|
|
|
|
2019-10-08 20:47:45 +02:00
|
|
|
proc renderReplyThread(thread: Chain; prefs: Prefs; path: string): VNode =
|
2019-07-11 00:42:31 +02:00
|
|
|
buildHtml(tdiv(class="reply thread thread-line")):
|
2019-08-23 02:15:25 +02:00
|
|
|
for i, tweet in thread.content:
|
|
|
|
let last = (i == thread.content.high and thread.more == 0)
|
2019-09-05 22:40:36 +02:00
|
|
|
renderTweet(tweet, prefs, path, index=i, last=last)
|
2019-07-11 00:42:31 +02:00
|
|
|
|
|
|
|
if thread.more != 0:
|
2019-08-23 01:20:00 +02:00
|
|
|
renderMoreReplies(thread)
|
2019-07-11 00:42:31 +02:00
|
|
|
|
2019-09-05 22:40:36 +02:00
|
|
|
proc renderConversation*(conversation: Conversation; prefs: Prefs; path: string): VNode =
|
2019-07-11 00:42:31 +02:00
|
|
|
let hasAfter = conversation.after != nil
|
2019-09-13 19:52:05 +02:00
|
|
|
buildHtml(tdiv(class="conversation")):
|
2019-07-11 00:42:31 +02:00
|
|
|
tdiv(class="main-thread"):
|
|
|
|
if conversation.before != nil:
|
|
|
|
tdiv(class="before-tweet thread-line"):
|
2019-08-23 02:15:25 +02:00
|
|
|
for i, tweet in conversation.before.content:
|
2019-09-05 22:40:36 +02:00
|
|
|
renderTweet(tweet, prefs, path, index=i)
|
2019-07-11 00:42:31 +02:00
|
|
|
|
2019-10-22 09:17:58 +02:00
|
|
|
tdiv(class="main-tweet", id="m"):
|
2019-07-11 00:42:31 +02:00
|
|
|
let afterClass = if hasAfter: "thread thread-line" else: ""
|
2019-10-08 13:28:57 +02:00
|
|
|
renderTweet(conversation.tweet, prefs, path, class=afterClass,
|
|
|
|
mainTweet=true)
|
2019-07-11 00:42:31 +02:00
|
|
|
|
|
|
|
if hasAfter:
|
|
|
|
tdiv(class="after-tweet thread-line"):
|
2019-08-23 02:15:25 +02:00
|
|
|
let total = conversation.after.content.high
|
2019-08-23 01:20:00 +02:00
|
|
|
let more = conversation.after.more
|
2019-08-23 02:15:25 +02:00
|
|
|
for i, tweet in conversation.after.content:
|
2019-09-05 22:40:36 +02:00
|
|
|
renderTweet(tweet, prefs, path, index=i, last=(i == total and more == 0))
|
2019-08-23 01:20:00 +02:00
|
|
|
|
|
|
|
if more != 0:
|
|
|
|
renderMoreReplies(conversation.after)
|
2019-07-11 00:42:31 +02:00
|
|
|
|
2019-09-24 15:39:04 +02:00
|
|
|
if not conversation.replies.beginning:
|
|
|
|
renderNewer(Query(), getLink(conversation.tweet))
|
|
|
|
|
|
|
|
if conversation.replies.content.len > 0:
|
2019-10-22 09:18:18 +02:00
|
|
|
tdiv(class="replies", id="r"):
|
2019-09-24 15:39:04 +02:00
|
|
|
for thread in conversation.replies.content:
|
2019-09-05 22:40:36 +02:00
|
|
|
if thread == nil: continue
|
|
|
|
renderReplyThread(thread, prefs, path)
|
2019-09-24 15:39:04 +02:00
|
|
|
|
|
|
|
if conversation.replies.hasMore:
|
2019-10-22 09:18:18 +02:00
|
|
|
renderMore(Query(), conversation.replies.minId, focus="#r")
|