From 01f9907aaf78d4dbffe08f6b7429ef0740844474 Mon Sep 17 00:00:00 2001 From: mikupls <93015331+mikupls@users.noreply.github.com> Date: Thu, 9 Mar 2023 05:30:41 +0100 Subject: [PATCH] show the count of 'more replies'. (#740) Co-authored-by: Daniel Valentine Co-authored-by: Matthew Esposito --- src/post.rs | 8 ++++++++ src/utils.rs | 1 + templates/comment.html | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/post.rs b/src/post.rs index aba692e..f2f5eaf 100644 --- a/src/post.rs +++ b/src/post.rs @@ -107,6 +107,13 @@ fn parse_comments(json: &serde_json::Value, post_link: &str, post_author: &str, let score = data["score"].as_i64().unwrap_or(0); + // The JSON API only provides comments up to some threshold. + // Further comments have to be loaded by subsequent requests. + // The "kind" value will be "more" and the "count" + // shows how many more (sub-)comments exist in the respective nesting level. + // Note that in certain (seemingly random) cases, the count is simply wrong. + let more_count = data["count"].as_i64().unwrap_or_default(); + // If this comment contains replies, handle those too let replies: Vec = if data["replies"].is_object() { parse_comments(&data["replies"], post_link, post_author, highlighted_comment, filters, req) @@ -177,6 +184,7 @@ fn parse_comments(json: &serde_json::Value, post_link: &str, post_author: &str, awards, collapsed, is_filtered, + more_count, prefs: Preferences::new(req), } }) diff --git a/src/utils.rs b/src/utils.rs index 39eca07..e6cb2f7 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -377,6 +377,7 @@ pub struct Comment { pub awards: Awards, pub collapsed: bool, pub is_filtered: bool, + pub more_count: i64, pub prefs: Preferences, } diff --git a/templates/comment.html b/templates/comment.html index d9b9c68..f3d0f27 100644 --- a/templates/comment.html +++ b/templates/comment.html @@ -1,7 +1,7 @@ {% import "utils.html" as utils %} {% if kind == "more" && parent_kind == "t1" %} -→ More replies +→ More replies ({{ more_count }}) {% else if kind == "t1" %}