From d45545cd539d16cfb0d7353831bd79044fd9345a Mon Sep 17 00:00:00 2001 From: Zed Date: Sat, 14 Feb 2026 02:24:24 +0100 Subject: [PATCH] Fix "Replying to" parsing --- src/parser.nim | 17 +++++++++++++---- src/views/tweet.nim | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/parser.nim b/src/parser.nim index c4e25a6..0ea91bc 100644 --- a/src/parser.nim +++ b/src/parser.nim @@ -283,7 +283,8 @@ proc parseCard(js: JsonNode; urls: JsonNode): Card = result.url.len == 0 or result.url.startsWith("card://"): result.url = getPicUrl(result.image) -proc parseTweet(js: JsonNode; jsCard: JsonNode = newJNull()): Tweet = +proc parseTweet(js: JsonNode; jsCard: JsonNode = newJNull(); + replyId: int64 = 0): Tweet = if js.isNull: return let time = @@ -307,6 +308,9 @@ proc parseTweet(js: JsonNode; jsCard: JsonNode = newJNull()): Tweet = ) ) + if result.replyId == 0: + result.replyId = replyId + # fix for pinned threads if result.hasThread and result.threadId == 0: result.threadId = js{"self_thread", "id_str"}.getId @@ -402,12 +406,17 @@ proc parseGraphTweet(js: JsonNode): Tweet = "binding_values": %bindingObj } - result = parseTweet(js{"legacy"}, jsCard) + var replyId = 0 + with restId, js{"reply_to_results", "rest_id"}: + replyId = restId.getId + + result = parseTweet(js{"legacy"}, jsCard, replyId) result.id = js{"rest_id"}.getId result.user = parseGraphUser(js{"core"}) - if result.replyId == 0: - result.replyId = js{"reply_to_results", "rest_id"}.getId + if result.reply.len == 0: + with replyTo, js{"reply_to_user_results", "result", "core", "screen_name"}: + result.reply = @[replyTo.getStr] with count, js{"views", "count"}: result.stats.views = count.getStr("0").parseInt diff --git a/src/views/tweet.nim b/src/views/tweet.nim index 0c6c6a1..2db01c1 100644 --- a/src/views/tweet.nim +++ b/src/views/tweet.nim @@ -307,7 +307,7 @@ proc renderTweet*(tweet: Tweet; prefs: Prefs; path: string; class=""; index=0; renderHeader(tweet, retweet, pinned, prefs) if not afterTweet and index == 0 and tweet.reply.len > 0 and - (tweet.reply.len > 1 or tweet.reply[0] != tweet.user.username): + (tweet.reply.len > 1 or tweet.reply[0] != tweet.user.username or pinned): renderReply(tweet) var tweetClass = "tweet-content media-body"