From c60280415e9bfa77d9b275c49d60515800f457f9 Mon Sep 17 00:00:00 2001 From: Zed Date: Mon, 1 Jul 2019 23:22:00 +0200 Subject: [PATCH] Minor retweet refactor --- src/parser.nim | 6 ++++-- src/types.nim | 7 +++++-- src/views/tweet.nimf | 4 ++-- src/views/user.nimf | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/parser.nim b/src/parser.nim index ac26443..a6d030e 100644 --- a/src/parser.nim +++ b/src/parser.nim @@ -73,8 +73,10 @@ proc parseTweet*(node: XmlNode): Tweet = let by = tweet.selectText(".js-retweet-text > a > b") if by.len > 0: - result.retweetBy = some(by.stripText()) - result.retweetId = some(tweet.attr("data-retweet-id")) + result.retweet = some(Retweet( + by: stripText(by), + id: tweet.attr("data-retweet-id") + )) let quote = tweet.select(".QuoteTweet-innerContainer") if quote != nil: diff --git a/src/types.nim b/src/types.nim index dadb88c..de15075 100644 --- a/src/types.nim +++ b/src/types.nim @@ -62,6 +62,10 @@ type thumb*: Option[string] badge*: Option[string] + Retweet* = object + by*: string + id*: string + Tweet* = ref object id*: string profile*: Profile @@ -72,9 +76,8 @@ type retweets*: string likes*: string pinned*: bool + retweet*: Option[Retweet] quote*: Option[Quote] - retweetBy*: Option[string] - retweetId*: Option[string] gif*: Option[Gif] video*: Option[Video] photos*: seq[string] diff --git a/src/views/tweet.nimf b/src/views/tweet.nimf index bcee4ab..7ff9603 100644 --- a/src/views/tweet.nimf +++ b/src/views/tweet.nimf @@ -3,9 +3,9 @@ #import ../types, ../formatters, ../utils # #proc renderHeading(tweet: Tweet): string = -#if tweet.retweetBy.isSome: +#if tweet.retweet.isSome:
- 🔄 ${tweet.retweetBy.get()} retweeted + 🔄 ${get(tweet.retweet).by} retweeted
#end if #if tweet.pinned: diff --git a/src/views/user.nimf b/src/views/user.nimf index 17e20c2..9b700b2 100644 --- a/src/views/user.nimf +++ b/src/views/user.nimf @@ -61,7 +61,7 @@ # #for tweet in timeline.tweets: #if tweet.id in retweets: continue - #elif tweet.retweetBy.isSome: retweets.add tweet.id + #elif tweet.retweet.isSome: retweets.add tweet.id #end if ${renderTweet(tweet, "timeline-tweet")} #end for