Skip to content

Commit

Permalink
simplify comments adjacency map
Browse files Browse the repository at this point in the history
  • Loading branch information
nain-F49FF806 committed Apr 27, 2024
1 parent ae2c7ea commit b428395
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/privatebin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,14 @@ impl Paste {
};
Ok(decrypted_comments)
}

/// Returns a mapping: comment.id -> [children comment.id]
pub fn comments_adjacency_map(&self) -> PbResult<CommentsAdjacencyMap> {
let mut comment_adjacency: HashMap<String, Vec<String>> = 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);
}
}
Expand Down Expand Up @@ -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())
}
}
Expand Down

0 comments on commit b428395

Please sign in to comment.