1
0
mirror of https://github.com/spikecodes/libreddit synced 2024-12-27 02:55:38 +01:00

Use Reveddit to show removed posts/comments. Closes #299

This commit is contained in:
spikecodes 2021-12-27 19:40:35 -08:00
parent b3d4f6f91c
commit db3196df5a
No known key found for this signature in database
GPG Key ID: 004CECFF9B463BCB
3 changed files with 20 additions and 5 deletions

2
Cargo.lock generated
View File

@ -572,7 +572,7 @@ checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125"
[[package]] [[package]]
name = "libreddit" name = "libreddit"
version = "0.20.5" version = "0.21.0"
dependencies = [ dependencies = [
"askama", "askama",
"async-recursion", "async-recursion",

View File

@ -3,7 +3,7 @@ name = "libreddit"
description = " Alternative private front-end to Reddit" description = " Alternative private front-end to Reddit"
license = "AGPL-3.0" license = "AGPL-3.0"
repository = "https://github.com/spikecodes/libreddit" repository = "https://github.com/spikecodes/libreddit"
version = "0.20.5" version = "0.21.0"
authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"] authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"]
edition = "2021" edition = "2021"

View File

@ -97,12 +97,22 @@ async fn parse_post(json: &serde_json::Value) -> Post {
let awards: Awards = Awards::parse(&post["data"]["all_awardings"]); let awards: Awards = Awards::parse(&post["data"]["all_awardings"]);
let permalink = val(post, "permalink");
let body = if val(post, "removed_by_category") == "moderator" {
format!("<div class=\"md\"><p>[removed] — <a href=\"https://www.reveddit.com{}\">view removed post</a></p></div>", permalink)
} else {
rewrite_urls(&val(post, "selftext_html")).replace("\\", "")
};
dbg!(val(post, "permalink"));
// Build a post using data parsed from Reddit post API // Build a post using data parsed from Reddit post API
Post { Post {
id: val(post, "id"), id: val(post, "id"),
title: esc!(post, "title"), title: esc!(post, "title"),
community: val(post, "subreddit"), community: val(post, "subreddit"),
body: rewrite_urls(&val(post, "selftext_html")).replace("\\", ""), body,
author: Author { author: Author {
name: val(post, "author"), name: val(post, "author"),
flair: Flair { flair: Flair {
@ -117,7 +127,7 @@ async fn parse_post(json: &serde_json::Value) -> Post {
}, },
distinguished: val(post, "distinguished"), distinguished: val(post, "distinguished"),
}, },
permalink: val(post, "permalink"), permalink,
score: format_num(score), score: format_num(score),
upvote_ratio: ratio as i64, upvote_ratio: ratio as i64,
post_type, 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 edited = data["edited"].as_f64().map_or((String::new(), String::new()), time);
let score = data["score"].as_i64().unwrap_or(0); 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 // If this comment contains replies, handle those too
let replies: Vec<Comment> = if data["replies"].is_object() { let replies: Vec<Comment> = 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 id = val(&comment, "id");
let highlighted = id == highlighted_comment; let highlighted = id == highlighted_comment;
let body = if val(&comment, "author") == "[deleted]" && val(&comment, "body") == "[removed]" {
format!("<div class=\"md\"><p>[removed] — <a href=\"https://www.reveddit.com{}{}\">view removed comment</a></p></div>", post_link, id)
} else {
rewrite_urls(&val(&comment, "body_html")).to_string()
};
let author = Author { let author = Author {
name: val(&comment, "author"), name: val(&comment, "author"),
flair: Flair { flair: Flair {