Support media tags

This commit is contained in:
Zed
2019-12-21 05:07:50 +01:00
parent 80acfbc40d
commit 80d6191e74
11 changed files with 52 additions and 14 deletions

View File

@@ -107,6 +107,7 @@ proc parseTweet*(node: XmlNode): Tweet =
profile: parseTweetProfile(tweet),
stats: parseTweetStats(tweet),
reply: parseTweetReply(tweet),
mediaTags: getMediaTags(tweet),
hasThread: tweet.select(".content > .self-thread-context") != nil,
pinned: "pinned" in tweet.attr("class"),
available: true

View File

@@ -1,4 +1,4 @@
import xmltree, strtabs, strformat, strutils, times, uri, options
import xmltree, strtabs, strformat, strutils, times, uri, options, json
import regex
import types, formatters
@@ -276,3 +276,12 @@ proc getMoreReplies*(node: XmlNode): int64 =
result = parseBiggestInt(text.split(" ")[0])
except:
result = -1
proc getMediaTags*(node: XmlNode): seq[Profile] =
let usernames = node.attr("data-tagged")
if usernames.len == 0: return
let users = parseJson(node.attr("data-reply-to-users-json"))
for user in users:
let un = user["screen_name"].getStr
if un notin usernames: continue
result.add Profile(username: un, fullname: user["name"].getStr)

View File

@@ -110,6 +110,24 @@
}
}
.media-tag-block {
padding-top: 5px;
pointer-events: all;
color: var(--fg_faded);
.icon-container {
padding-right: 2px;
}
.media-tag, .icon-container {
color: var(--fg_faded);
}
}
.timeline-container .media-tag-block {
font-size: 13px;
}
.replying-to {
color: var(--fg_faded);
margin: -2px 0 4px;

View File

@@ -150,6 +150,7 @@ type
stats*: TweetStats
retweet*: Option[Retweet]
attribution*: Option[Profile]
mediaTags*: seq[Profile]
quote*: Option[Quote]
card*: Option[Card]
gif*: Option[Gif]

View File

@@ -195,6 +195,15 @@ proc renderAttribution(profile: Profile): VNode =
img(class="avatar", width="20", height="20", src=avatarUrl)
strong: text profile.fullname
proc renderMediaTags(tags: seq[Profile]): VNode =
buildHtml(tdiv(class="media-tag-block")):
icon "user"
for i, p in tags:
a(class="media-tag", href=("/" & p.username), title=p.username):
text p.fullname
if i < tags.high:
text ", "
proc renderQuoteMedia(quote: Quote): VNode =
buildHtml(tdiv(class="quote-media-container")):
if quote.thumb.len > 0:
@@ -286,6 +295,9 @@ proc renderTweet*(tweet: Tweet; prefs: Prefs; path: string; class="";
if mainTweet:
p(class="tweet-published"): text getTweetTime(tweet)
if tweet.mediaTags.len > 0:
renderMediaTags(tweet.mediaTags)
if not prefs.hideTweetStats:
renderStats(tweet.stats, views)