From db3196df5a23d51eb1daa29f653e4f39dc9c0f02 Mon Sep 17 00:00:00 2001 From: spikecodes <19519553+spikecodes@users.noreply.github.com> Date: Mon, 27 Dec 2021 19:40:35 -0800 Subject: [PATCH] Use Reveddit to show removed posts/comments. Closes #299 --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/post.rs | 21 ++++++++++++++++++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index edf3082..25c23dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -572,7 +572,7 @@ checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" [[package]] name = "libreddit" -version = "0.20.5" +version = "0.21.0" dependencies = [ "askama", "async-recursion", diff --git a/Cargo.toml b/Cargo.toml index 72c71cd..59278e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "libreddit" description = " Alternative private front-end to Reddit" license = "AGPL-3.0" repository = "https://github.com/spikecodes/libreddit" -version = "0.20.5" +version = "0.21.0" authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"] edition = "2021" diff --git a/src/post.rs b/src/post.rs index ff430fc..d176f7d 100644 --- a/src/post.rs +++ b/src/post.rs @@ -97,12 +97,22 @@ async fn parse_post(json: &serde_json::Value) -> Post { let awards: Awards = Awards::parse(&post["data"]["all_awardings"]); + let permalink = val(post, "permalink"); + + let body = if val(post, "removed_by_category") == "moderator" { + format!("

[removed] — view removed post

", permalink) + } else { + rewrite_urls(&val(post, "selftext_html")).replace("\\", "") + }; + + dbg!(val(post, "permalink")); + // Build a post using data parsed from Reddit post API Post { id: val(post, "id"), title: esc!(post, "title"), community: val(post, "subreddit"), - body: rewrite_urls(&val(post, "selftext_html")).replace("\\", ""), + body, author: Author { name: val(post, "author"), flair: Flair { @@ -117,7 +127,7 @@ async fn parse_post(json: &serde_json::Value) -> Post { }, distinguished: val(post, "distinguished"), }, - permalink: val(post, "permalink"), + permalink, score: format_num(score), upvote_ratio: ratio as i64, post_type, @@ -174,7 +184,6 @@ fn parse_comments(json: &serde_json::Value, post_link: &str, post_author: &str, let edited = data["edited"].as_f64().map_or((String::new(), String::new()), time); let score = data["score"].as_i64().unwrap_or(0); - let body = rewrite_urls(&val(&comment, "body_html")); // If this comment contains replies, handle those too let replies: Vec = if data["replies"].is_object() { @@ -191,6 +200,12 @@ fn parse_comments(json: &serde_json::Value, post_link: &str, post_author: &str, let id = val(&comment, "id"); let highlighted = id == highlighted_comment; + let body = if val(&comment, "author") == "[deleted]" && val(&comment, "body") == "[removed]" { + format!("

[removed] — view removed comment

", post_link, id) + } else { + rewrite_urls(&val(&comment, "body_html")).to_string() + }; + let author = Author { name: val(&comment, "author"), flair: Flair {