From b031ea762ea32c712ea85b7524f73bde76564a5f Mon Sep 17 00:00:00 2001 From: 110Percent <110percent@riseup.net> Date: Sat, 26 Feb 2022 13:37:17 -0500 Subject: [PATCH] Add source label to main tweets --- src/parser.nim | 3 +++ src/types.nim | 1 + src/views/tweet.nim | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/parser.nim b/src/parser.nim index d3d62cf..1f16d12 100644 --- a/src/parser.nim +++ b/src/parser.nim @@ -3,6 +3,7 @@ import strutils, options, tables, times, math import packedjson, packedjson/deserialiser import types, parserutils, utils import experimental/parser/unifiedcard +import std/strutils proc parseUser(js: JsonNode; id=""): User = if js.isNull: return @@ -183,12 +184,14 @@ proc parseCard(js: JsonNode; urls: JsonNode): Card = proc parseTweet(js: JsonNode): Tweet = if js.isNull: return + result = Tweet( id: js{"id_str"}.getId, threadId: js{"conversation_id_str"}.getId, replyId: js{"in_reply_to_status_id_str"}.getId, text: js{"full_text"}.getStr, time: js{"created_at"}.getTime, + source: js{"source"}.getStr.split(">")[1].split("<")[0], hasThread: js{"self_thread"}.notNull, available: true, user: User(id: js{"user_id_str"}.getStr), diff --git a/src/types.nim b/src/types.nim index 9a6ad7f..f28e90a 100644 --- a/src/types.nim +++ b/src/types.nim @@ -175,6 +175,7 @@ type tombstone*: string location*: string stats*: TweetStats + source*: string retweet*: Option[Tweet] attribution*: Option[User] mediaTags*: seq[User] diff --git a/src/views/tweet.nim b/src/views/tweet.nim index 8b712a6..b6f8d7e 100644 --- a/src/views/tweet.nim +++ b/src/views/tweet.nim @@ -344,7 +344,7 @@ proc renderTweet*(tweet: Tweet; prefs: Prefs; path: string; class=""; index=0; renderQuote(tweet.quote.get(), prefs, path) if mainTweet: - p(class="tweet-published"): text getTime(tweet) + p(class="tweet-published"): text getTime(tweet) & " ยท " & tweet.source if tweet.mediaTags.len > 0: renderMediaTags(tweet.mediaTags)