2019-10-26 13:34:30 +00:00
|
|
|
import strutils, sequtils, strformat, options
|
2019-07-10 22:42:31 +00:00
|
|
|
import karax/[karaxdsl, vdom, vstyles]
|
|
|
|
|
|
|
|
import renderutils
|
2019-09-06 00:42:35 +00:00
|
|
|
import ".."/[types, utils, formatters]
|
2019-07-10 22:42:31 +00:00
|
|
|
|
|
|
|
proc renderHeader(tweet: Tweet): VNode =
|
|
|
|
buildHtml(tdiv):
|
|
|
|
if tweet.retweet.isSome:
|
2019-09-23 22:59:13 +00:00
|
|
|
tdiv(class="retweet-header"):
|
2019-08-19 19:18:18 +00:00
|
|
|
span: icon "retweet", get(tweet.retweet).by & " retweeted"
|
2019-08-15 02:00:40 +00:00
|
|
|
|
2019-07-10 22:42:31 +00:00
|
|
|
if tweet.pinned:
|
|
|
|
tdiv(class="pinned"):
|
2019-08-15 02:00:40 +00:00
|
|
|
span: icon "pin", "Pinned Tweet"
|
2019-07-10 22:42:31 +00:00
|
|
|
|
|
|
|
tdiv(class="tweet-header"):
|
2019-08-12 15:02:07 +00:00
|
|
|
a(class="tweet-avatar", href=("/" & tweet.profile.username)):
|
|
|
|
genImg(tweet.profile.getUserpic("_bigger"), class="avatar")
|
2019-07-10 22:42:31 +00:00
|
|
|
|
2019-08-12 15:02:07 +00:00
|
|
|
tdiv(class="tweet-name-row"):
|
2019-07-10 22:42:31 +00:00
|
|
|
tdiv(class="fullname-and-username"):
|
|
|
|
linkUser(tweet.profile, class="fullname")
|
|
|
|
linkUser(tweet.profile, class="username")
|
|
|
|
|
|
|
|
span(class="tweet-date"):
|
|
|
|
a(href=getLink(tweet), title=tweet.getTime()):
|
|
|
|
text tweet.shortTime
|
|
|
|
|
|
|
|
proc renderAlbum(tweet: Tweet): VNode =
|
|
|
|
let
|
|
|
|
groups = if tweet.photos.len < 3: @[tweet.photos]
|
|
|
|
else: tweet.photos.distribute(2)
|
|
|
|
|
2019-09-19 01:02:56 +00:00
|
|
|
if groups.len == 1 and groups[0].len == 1:
|
|
|
|
buildHtml(tdiv(class="single-image")):
|
|
|
|
tdiv(class="attachments gallery-row"):
|
|
|
|
a(href=getPicUrl(groups[0][0] & "?name=orig"), class="still-image",
|
|
|
|
target="_blank"):
|
|
|
|
genImg(groups[0][0])
|
|
|
|
else:
|
|
|
|
buildHtml(tdiv(class="attachments")):
|
|
|
|
for i, photos in groups:
|
|
|
|
let margin = if i > 0: ".25em" else: ""
|
|
|
|
let flex = if photos.len > 1 or groups.len > 1: "flex" else: "block"
|
|
|
|
tdiv(class="gallery-row", style={marginTop: margin}):
|
|
|
|
for photo in photos:
|
|
|
|
tdiv(class="attachment image"):
|
|
|
|
a(href=getPicUrl(photo & "?name=orig"), class="still-image",
|
|
|
|
target="_blank", style={display: flex}):
|
|
|
|
genImg(photo)
|
2019-07-10 22:42:31 +00:00
|
|
|
|
2019-08-19 01:28:04 +00:00
|
|
|
proc isPlaybackEnabled(prefs: Prefs; video: Video): bool =
|
|
|
|
case video.playbackType
|
|
|
|
of mp4: prefs.mp4Playback
|
|
|
|
of m3u8, vmap: prefs.hlsPlayback
|
|
|
|
|
2019-09-05 20:40:36 +00:00
|
|
|
proc renderVideoDisabled(video: Video; path: string): VNode =
|
2019-08-19 01:28:04 +00:00
|
|
|
buildHtml(tdiv):
|
2019-09-13 10:27:04 +00:00
|
|
|
img(src=getPicUrl(video.thumb))
|
2019-08-19 01:28:04 +00:00
|
|
|
tdiv(class="video-overlay"):
|
|
|
|
case video.playbackType
|
|
|
|
of mp4:
|
|
|
|
p: text "mp4 playback disabled in preferences"
|
|
|
|
of m3u8, vmap:
|
2019-09-05 20:53:23 +00:00
|
|
|
buttonReferer "/enablehls", "Enable hls playback", path
|
2019-08-19 01:28:04 +00:00
|
|
|
|
2019-08-19 20:03:00 +00:00
|
|
|
proc renderVideoUnavailable(video: Video): VNode =
|
|
|
|
buildHtml(tdiv):
|
2019-09-13 10:27:04 +00:00
|
|
|
img(src=getPicUrl(video.thumb))
|
2019-08-19 20:03:00 +00:00
|
|
|
tdiv(class="video-overlay"):
|
|
|
|
case video.reason
|
|
|
|
of "dmcaed":
|
|
|
|
p: text "This media has been disabled in response to a report by the copyright owner"
|
|
|
|
else:
|
|
|
|
p: text "This media is unavailable"
|
|
|
|
|
2019-09-05 20:40:36 +00:00
|
|
|
proc renderVideo(video: Video; prefs: Prefs; path: string): VNode =
|
2019-10-26 13:50:42 +00:00
|
|
|
let container =
|
|
|
|
if video.description.len > 0 or video.title.len > 0: " card-container"
|
|
|
|
else: ""
|
2019-11-04 22:13:58 +00:00
|
|
|
buildHtml(tdiv(class="attachments card")):
|
2019-10-26 13:50:42 +00:00
|
|
|
tdiv(class="gallery-video" & container):
|
2019-07-10 22:42:31 +00:00
|
|
|
tdiv(class="attachment video-container"):
|
2019-09-13 10:27:04 +00:00
|
|
|
let thumb = getPicUrl(video.thumb)
|
2019-08-19 20:03:00 +00:00
|
|
|
if not video.available:
|
|
|
|
renderVideoUnavailable(video)
|
|
|
|
elif not prefs.isPlaybackEnabled(video):
|
2019-09-05 20:40:36 +00:00
|
|
|
renderVideoDisabled(video, path)
|
2019-08-19 20:03:00 +00:00
|
|
|
else:
|
2019-09-13 10:27:04 +00:00
|
|
|
let source = getVidUrl(video.url)
|
2019-08-19 01:28:04 +00:00
|
|
|
case video.playbackType
|
|
|
|
of mp4:
|
|
|
|
if prefs.muteVideos:
|
|
|
|
video(poster=thumb, controls="", muted=""):
|
|
|
|
source(src=source, `type`="video/mp4")
|
|
|
|
else:
|
|
|
|
video(poster=thumb, controls=""):
|
|
|
|
source(src=source, `type`="video/mp4")
|
|
|
|
of m3u8, vmap:
|
2019-08-19 18:25:00 +00:00
|
|
|
video(poster=thumb, data-url=source, data-autoload="false")
|
|
|
|
verbatim "<div class=\"video-overlay\" onclick=\"playVideo(this)\">"
|
2019-08-19 19:27:28 +00:00
|
|
|
verbatim "<div class=\"overlay-circle\">"
|
|
|
|
verbatim "<span class=\"overlay-triangle\"</span></div></div>"
|
2019-10-26 13:50:42 +00:00
|
|
|
if container.len > 0:
|
|
|
|
tdiv(class="card-content"):
|
|
|
|
h2(class="card-title"): text video.title
|
|
|
|
if video.description.len > 0:
|
|
|
|
p(class="card-description"): text video.description
|
2019-08-13 17:44:29 +00:00
|
|
|
|
|
|
|
proc renderGif(gif: Gif; prefs: Prefs): VNode =
|
2019-07-10 22:42:31 +00:00
|
|
|
buildHtml(tdiv(class="attachments media-gif")):
|
|
|
|
tdiv(class="gallery-gif", style=style(maxHeight, "unset")):
|
|
|
|
tdiv(class="attachment"):
|
2019-09-13 10:27:04 +00:00
|
|
|
let thumb = getPicUrl(gif.thumb)
|
|
|
|
let url = getGifUrl(gif.url)
|
2019-08-13 17:44:29 +00:00
|
|
|
if prefs.autoplayGifs:
|
|
|
|
video(class="gif", poster=thumb, autoplay="", muted="", loop=""):
|
|
|
|
source(src=url, `type`="video/mp4")
|
|
|
|
else:
|
|
|
|
video(class="gif", poster=thumb, controls="", muted="", loop=""):
|
|
|
|
source(src=url, `type`="video/mp4")
|
2019-07-10 22:42:31 +00:00
|
|
|
|
|
|
|
proc renderPoll(poll: Poll): VNode =
|
|
|
|
buildHtml(tdiv(class="poll")):
|
|
|
|
for i in 0 ..< poll.options.len:
|
|
|
|
let leader = if poll.leader == i: " leader" else: ""
|
|
|
|
let perc = $poll.values[i] & "%"
|
|
|
|
tdiv(class=("poll-meter" & leader)):
|
|
|
|
span(class="poll-choice-bar", style=style(width, perc))
|
|
|
|
span(class="poll-choice-value"): text perc
|
|
|
|
span(class="poll-choice-option"): text poll.options[i]
|
|
|
|
span(class="poll-info"):
|
|
|
|
text $poll.votes & " votes • " & poll.status
|
|
|
|
|
2019-07-15 14:03:01 +00:00
|
|
|
proc renderCardImage(card: Card): VNode =
|
|
|
|
buildHtml(tdiv(class="card-image-container")):
|
|
|
|
tdiv(class="card-image"):
|
2019-09-13 10:27:04 +00:00
|
|
|
img(src=getPicUrl(get(card.image)))
|
2019-07-15 14:03:01 +00:00
|
|
|
if card.kind == player:
|
|
|
|
tdiv(class="card-overlay"):
|
2019-08-19 19:27:28 +00:00
|
|
|
tdiv(class="overlay-circle"):
|
|
|
|
span(class="overlay-triangle")
|
2019-07-15 14:03:01 +00:00
|
|
|
|
2019-08-19 18:53:57 +00:00
|
|
|
proc renderCardContent(card: Card): VNode =
|
|
|
|
buildHtml(tdiv(class="card-content")):
|
|
|
|
h2(class="card-title"): text card.title
|
|
|
|
p(class="card-description"): text card.text
|
|
|
|
span(class="card-destination"): text card.dest
|
|
|
|
|
2019-09-05 20:40:36 +00:00
|
|
|
proc renderCard(card: Card; prefs: Prefs; path: string): VNode =
|
2019-11-08 21:52:34 +00:00
|
|
|
const largeCards = {summaryLarge, liveEvent, promoWebsite,
|
|
|
|
promoVideo, promoVideoConvo}
|
2019-07-15 11:41:27 +00:00
|
|
|
let large = if card.kind in largeCards: " large" else: ""
|
2019-08-19 18:53:57 +00:00
|
|
|
let url = replaceUrl(card.url, prefs)
|
2019-07-15 11:41:27 +00:00
|
|
|
|
|
|
|
buildHtml(tdiv(class=("card" & large))):
|
2019-08-19 18:53:57 +00:00
|
|
|
if card.video.isSome:
|
|
|
|
tdiv(class="card-container"):
|
2019-09-05 20:40:36 +00:00
|
|
|
renderVideo(get(card.video), prefs, path)
|
2019-08-19 18:53:57 +00:00
|
|
|
a(class="card-content-container", href=url):
|
|
|
|
renderCardContent(card)
|
|
|
|
else:
|
|
|
|
a(class="card-container", href=url):
|
|
|
|
if card.image.isSome:
|
|
|
|
renderCardImage(card)
|
|
|
|
tdiv(class="card-content-container"):
|
|
|
|
renderCardContent(card)
|
2019-07-15 11:41:27 +00:00
|
|
|
|
2019-08-19 19:18:18 +00:00
|
|
|
proc renderStats(stats: TweetStats; views: string): VNode =
|
2019-07-10 22:42:31 +00:00
|
|
|
buildHtml(tdiv(class="tweet-stats")):
|
2019-08-15 02:00:40 +00:00
|
|
|
span(class="tweet-stat"): icon "comment", $stats.replies
|
2019-08-19 19:18:18 +00:00
|
|
|
span(class="tweet-stat"): icon "retweet", $stats.retweets
|
2019-10-08 18:56:54 +00:00
|
|
|
span(class="tweet-stat"): icon "heart", $stats.likes
|
2019-08-19 19:18:18 +00:00
|
|
|
if views.len > 0:
|
|
|
|
span(class="tweet-stat"): icon "play", views
|
2019-07-10 22:42:31 +00:00
|
|
|
|
|
|
|
proc renderReply(tweet: Tweet): VNode =
|
|
|
|
buildHtml(tdiv(class="replying-to")):
|
|
|
|
text "Replying to "
|
|
|
|
for i, u in tweet.reply:
|
|
|
|
if i > 0: text " "
|
|
|
|
a(href=("/" & u)): text "@" & u
|
|
|
|
|
|
|
|
proc renderReply(quote: Quote): VNode =
|
|
|
|
buildHtml(tdiv(class="replying-to")):
|
|
|
|
text "Replying to "
|
|
|
|
for i, u in quote.reply:
|
|
|
|
if i > 0: text " "
|
|
|
|
a(href=("/" & u)): text "@" & u
|
|
|
|
|
2019-10-26 14:37:58 +00:00
|
|
|
proc renderAttribution(profile: Profile): VNode =
|
2019-10-28 15:27:27 +00:00
|
|
|
let avatarUrl = getPicUrl(profile.getUserpic("_200x200"))
|
2019-10-26 14:37:58 +00:00
|
|
|
buildHtml(a(class="attribution", href=("/" & profile.username))):
|
2019-10-28 15:27:27 +00:00
|
|
|
img(class="avatar", width="20", height="20", src=avatarUrl)
|
2019-10-26 14:37:58 +00:00
|
|
|
strong: text profile.fullname
|
|
|
|
|
2019-07-10 22:42:31 +00:00
|
|
|
proc renderQuoteMedia(quote: Quote): VNode =
|
|
|
|
buildHtml(tdiv(class="quote-media-container")):
|
|
|
|
if quote.thumb.len > 0:
|
|
|
|
tdiv(class="quote-media"):
|
|
|
|
genImg(quote.thumb)
|
|
|
|
if quote.badge.len > 0:
|
|
|
|
tdiv(class="quote-badge"):
|
|
|
|
tdiv(class="quote-badge-text"): text quote.badge
|
|
|
|
elif quote.sensitive:
|
|
|
|
tdiv(class="quote-sensitive"):
|
2019-08-15 02:00:40 +00:00
|
|
|
icon "attention", class="quote-sensitive-icon"
|
2019-07-10 22:42:31 +00:00
|
|
|
|
2019-08-15 13:51:20 +00:00
|
|
|
proc renderQuote(quote: Quote; prefs: Prefs): VNode =
|
2019-07-10 22:42:31 +00:00
|
|
|
if not quote.available:
|
|
|
|
return buildHtml(tdiv(class="quote unavailable")):
|
|
|
|
tdiv(class="unavailable-quote"):
|
2019-09-08 12:34:26 +00:00
|
|
|
if quote.tombstone.len > 0:
|
|
|
|
text quote.tombstone
|
|
|
|
else:
|
|
|
|
text "This tweet is unavailable"
|
2019-07-10 22:42:31 +00:00
|
|
|
|
|
|
|
buildHtml(tdiv(class="quote")):
|
|
|
|
a(class="quote-link", href=getLink(quote))
|
|
|
|
|
|
|
|
if quote.thumb.len > 0 or quote.sensitive:
|
|
|
|
renderQuoteMedia(quote)
|
|
|
|
|
|
|
|
tdiv(class="fullname-and-username"):
|
|
|
|
linkUser(quote.profile, class="fullname")
|
|
|
|
linkUser(quote.profile, class="username")
|
|
|
|
|
|
|
|
if quote.reply.len > 0:
|
|
|
|
renderReply(quote)
|
|
|
|
|
|
|
|
tdiv(class="quote-text"):
|
2019-10-09 14:06:51 +00:00
|
|
|
verbatim replaceUrl(quote.text, prefs)
|
2019-07-10 22:42:31 +00:00
|
|
|
|
|
|
|
if quote.hasThread:
|
2019-08-13 19:21:54 +00:00
|
|
|
a(class="show-thread", href=getLink(quote)):
|
2019-07-10 22:42:31 +00:00
|
|
|
text "Show this thread"
|
|
|
|
|
2019-09-05 20:40:36 +00:00
|
|
|
proc renderTweet*(tweet: Tweet; prefs: Prefs; path: string; class="";
|
2019-10-08 11:28:57 +00:00
|
|
|
index=0; total=(-1); last=false; showThread=false;
|
|
|
|
mainTweet=false): VNode =
|
2019-07-10 22:42:31 +00:00
|
|
|
var divClass = class
|
|
|
|
if index == total or last:
|
|
|
|
divClass = "thread-last " & class
|
|
|
|
|
|
|
|
if not tweet.available:
|
2019-09-19 01:19:06 +00:00
|
|
|
return buildHtml(tdiv(class=divClass & "unavailable timeline-item")):
|
|
|
|
tdiv(class="unavailable-box"):
|
|
|
|
if tweet.tombstone.len > 0:
|
|
|
|
text tweet.tombstone
|
|
|
|
else:
|
|
|
|
text "This tweet is unavailable"
|
2019-07-10 22:42:31 +00:00
|
|
|
|
2019-09-13 17:57:27 +00:00
|
|
|
buildHtml(tdiv(class=("timeline-item " & divClass))):
|
2019-10-08 18:54:16 +00:00
|
|
|
if not mainTweet:
|
|
|
|
a(class="tweet-link", href=getLink(tweet))
|
|
|
|
|
2019-09-13 17:57:27 +00:00
|
|
|
tdiv(class="tweet-body"):
|
|
|
|
var views = ""
|
|
|
|
renderHeader(tweet)
|
|
|
|
|
|
|
|
if index == 0 and tweet.reply.len > 0:
|
|
|
|
renderReply(tweet)
|
|
|
|
|
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(tweet.text, prefs)
|
2019-09-13 17:57:27 +00:00
|
|
|
|
2019-10-26 14:37:58 +00:00
|
|
|
if tweet.attribution.isSome:
|
|
|
|
renderAttribution(tweet.attribution.get())
|
|
|
|
|
2019-09-13 17:57:27 +00:00
|
|
|
if tweet.quote.isSome:
|
|
|
|
renderQuote(tweet.quote.get(), prefs)
|
|
|
|
|
|
|
|
if tweet.card.isSome:
|
|
|
|
renderCard(tweet.card.get(), prefs, path)
|
|
|
|
elif tweet.photos.len > 0:
|
|
|
|
renderAlbum(tweet)
|
|
|
|
elif tweet.video.isSome:
|
|
|
|
renderVideo(tweet.video.get(), prefs, path)
|
|
|
|
views = tweet.video.get().views
|
|
|
|
elif tweet.gif.isSome:
|
|
|
|
renderGif(tweet.gif.get(), prefs)
|
|
|
|
elif tweet.poll.isSome:
|
|
|
|
renderPoll(tweet.poll.get())
|
|
|
|
|
2019-10-08 11:28:57 +00:00
|
|
|
if mainTweet:
|
|
|
|
p(class="tweet-published"): text getTweetTime(tweet)
|
|
|
|
|
2019-09-13 17:57:27 +00:00
|
|
|
if not prefs.hideTweetStats:
|
|
|
|
renderStats(tweet.stats, views)
|
|
|
|
|
2019-09-19 01:51:15 +00:00
|
|
|
if showThread:
|
2019-10-23 07:47:15 +00:00
|
|
|
a(class="show-thread", href=("/i/status/" & $tweet.threadId)):
|
2019-09-13 17:57:27 +00:00
|
|
|
text "Show this thread"
|