From b428395f2c822eb6e8b2a2bd28ac3c59e9d438cb Mon Sep 17 00:00:00 2001 From: nain <126972030+nain-F49FF806@users.noreply.github.com> Date: Sat, 27 Apr 2024 08:55:39 +0200 Subject: [PATCH] simplify comments adjacency map --- src/privatebin.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/privatebin.rs b/src/privatebin.rs index 532cd91..c1f6860 100644 --- a/src/privatebin.rs +++ b/src/privatebin.rs @@ -195,17 +195,14 @@ impl Paste { }; Ok(decrypted_comments) } + /// Returns a mapping: comment.id -> [children comment.id] pub fn comments_adjacency_map(&self) -> PbResult { - let mut comment_adjacency: HashMap> = HashMap::new(); + let mut comment_adjacency: CommentsAdjacencyMap = HashMap::new(); if let Some(comments) = &self.comments { for c in comments { let id = c.id.clone(); - let parentid = if c.parentid == c.pasteid { - "".to_owned() - } else { - c.parentid.clone() - }; + let parentid = c.parentid.clone(); comment_adjacency.entry(parentid).or_default().push(id); } } @@ -239,7 +236,7 @@ impl Paste { } }) } - let top_level = format_comments_below_id("", decrypted_comments, comment_adjacency); + let top_level = format_comments_below_id(&self.id, decrypted_comments, comment_adjacency); serde_json::to_string_pretty(&top_level).map_err(|e| e.into()) } }