nitter/src/views/status.nim

76 lines
2.7 KiB
Nim
Raw Normal View History

2021-12-27 01:37:38 +00:00
# SPDX-License-Identifier: AGPL-3.0-only
import karax/[karaxdsl, vdom]
import ".."/[types, formatters]
import tweet, timeline
proc renderEarlier(thread: Chain): VNode =
buildHtml(tdiv(class="timeline-item more-replies earlier-replies")):
a(class="more-replies-text", href=getLink(thread.content[0])):
text "earlier replies"
proc renderMoreReplies(thread: Chain): VNode =
2019-09-24 14:34:50 +00:00
let link = getLink(thread.content[^1])
2019-09-13 17:57:27 +00:00
buildHtml(tdiv(class="timeline-item more-replies")):
2020-06-01 00:22:22 +00:00
if thread.content[^1].available:
2019-09-24 14:34:50 +00:00
a(class="more-replies-text", href=link):
text "more replies"
else:
a(class="more-replies-text"):
text "more replies"
proc renderReplyThread(thread: Chain; prefs: Prefs; path: string): VNode =
buildHtml(tdiv(class="reply thread thread-line")):
2019-08-23 00:15:25 +00:00
for i, tweet in thread.content:
let last = (i == thread.content.high and not thread.hasMore)
renderTweet(tweet, prefs, path, index=i, last=last)
if thread.hasMore:
renderMoreReplies(thread)
proc renderReplies*(replies: Result[Chain]; prefs: Prefs; path: string): VNode =
buildHtml(tdiv(class="replies", id="r")):
for thread in replies.content:
2020-06-01 00:22:22 +00:00
if thread.content.len == 0: continue
renderReplyThread(thread, prefs, path)
2020-06-01 00:22:22 +00:00
if replies.bottom.len > 0:
2021-12-28 07:07:15 +00:00
renderMore(Query(), replies.bottom, focus="#r")
2020-06-01 00:22:22 +00:00
proc renderConversation*(conv: Conversation; prefs: Prefs; path: string): VNode =
let hasAfter = conv.after.content.len > 0
let threadId = conv.tweet.threadId
2019-09-13 17:52:05 +00:00
buildHtml(tdiv(class="conversation")):
tdiv(class="main-thread"):
2020-06-01 00:22:22 +00:00
if conv.before.content.len > 0:
tdiv(class="before-tweet thread-line"):
2020-06-01 00:22:22 +00:00
let first = conv.before.content[0]
if threadId != first.id and (first.replyId > 0 or not first.available):
renderEarlier(conv.before)
for i, tweet in conv.before.content:
renderTweet(tweet, prefs, path, index=i)
2019-10-22 07:17:58 +00:00
tdiv(class="main-tweet", id="m"):
let afterClass = if hasAfter: "thread thread-line" else: ""
2020-06-01 00:22:22 +00:00
renderTweet(conv.tweet, prefs, path, class=afterClass, mainTweet=true)
if hasAfter:
tdiv(class="after-tweet thread-line"):
2020-06-01 00:22:22 +00:00
let
total = conv.after.content.high
hasMore = conv.after.hasMore
2020-06-01 00:22:22 +00:00
for i, tweet in conv.after.content:
renderTweet(tweet, prefs, path, index=i,
last=(i == total and not hasMore), afterTweet=true)
if hasMore:
2020-06-01 00:22:22 +00:00
renderMoreReplies(conv.after)
2020-06-01 00:22:22 +00:00
if not prefs.hideReplies:
if not conv.replies.beginning:
renderNewer(Query(), getLink(conv.tweet), focus="#r")
if conv.replies.content.len > 0 or conv.replies.bottom.len > 0:
renderReplies(conv.replies, prefs, path)
renderToTop(focus="#m")