diff --git a/src/post.rs b/src/post.rs index b4d577b..ef71d00 100644 --- a/src/post.rs +++ b/src/post.rs @@ -1,5 +1,5 @@ // CRATES -use crate::utils::{cookie, error, format_num, format_url, media, param, parse_rich_flair, prefs, request, rewrite_url, time, val, Comment, Flags, Flair, Post, Preferences}; +use crate::utils::*; use actix_web::{HttpRequest, HttpResponse}; use async_recursion::async_recursion; @@ -80,15 +80,18 @@ async fn parse_post(json: &serde_json::Value) -> Post { title: val(post, "title"), community: val(post, "subreddit"), body: rewrite_url(&val(post, "selftext_html")), - author: val(post, "author"), - author_flair: Flair { - flair_parts: parse_rich_flair( - val(post, "author_flair_type"), - post["data"]["author_flair_richtext"].as_array(), - post["data"]["author_flair_text"].as_str(), - ), - background_color: val(post, "author_flair_background_color"), - foreground_color: val(post, "author_flair_text_color"), + author: Author { + name: val(post, "author"), + flair: Flair { + flair_parts: parse_rich_flair( + val(post, "author_flair_type"), + post["data"]["author_flair_richtext"].as_array(), + post["data"]["author_flair_text"].as_str(), + ), + background_color: val(post, "author_flair_background_color"), + foreground_color: val(post, "author_flair_text_color"), + }, + distinguished: val(post, "distinguished"), }, permalink: val(post, "permalink"), score: format_num(score), @@ -150,20 +153,23 @@ async fn parse_comments(json: &serde_json::Value) -> Vec { comments.push(Comment { id: val(&comment, "id"), body, - author: val(&comment, "author"), + author: Author { + name: val(&comment, "author"), + flair: Flair { + flair_parts: parse_rich_flair( + val(&comment, "author_flair_type"), + comment["data"]["author_flair_richtext"].as_array(), + comment["data"]["author_flair_text"].as_str(), + ), + background_color: val(&comment, "author_flair_background_color"), + foreground_color: val(&comment, "author_flair_text_color"), + }, + distinguished: val(&comment, "distinguished"), + }, score: format_num(score), rel_time, created, replies, - flair: Flair { - flair_parts: parse_rich_flair( - val(&comment, "author_flair_type"), - comment["data"]["author_flair_richtext"].as_array(), - comment["data"]["author_flair_text"].as_str(), - ), - background_color: val(&comment, "author_flair_background_color"), - foreground_color: val(&comment, "author_flair_text_color"), - }, }); } diff --git a/src/utils.rs b/src/utils.rs index 1538c5a..102c0e7 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -13,6 +13,7 @@ use url::Url; // // STRUCTS // + // Post flair with content, background color and foreground color pub struct Flair { pub flair_parts: Vec, @@ -26,6 +27,12 @@ pub struct FlairPart { pub value: String, } +pub struct Author { + pub name: String, + pub flair: Flair, + pub distinguished: String, +} + // Post flags with nsfw and stickied pub struct Flags { pub nsfw: bool, @@ -38,8 +45,7 @@ pub struct Post { pub title: String, pub community: String, pub body: String, - pub author: String, - pub author_flair: Flair, + pub author: Author, pub permalink: String, pub score: String, pub upvote_ratio: i64, @@ -57,8 +63,7 @@ pub struct Post { pub struct Comment { pub id: String, pub body: String, - pub author: String, - pub flair: Flair, + pub author: Author, pub score: String, pub rel_time: String, pub created: String, @@ -308,15 +313,18 @@ pub async fn fetch_posts(path: &str, fallback_title: String) -> Result<(Vec + {% endblock %} @@ -21,9 +21,10 @@
- u/{{ item.author }} - {% if item.flair.flair_parts.len() > 0 %} - {% call utils::render_flair(item.flair.flair_parts) %} + + u/{{ item.author.name }} + {% if item.author.flair.flair_parts.len() > 0 %} + {% call utils::render_flair(item.author.flair.flair_parts) %} {% endif %} {{ item.rel_time }} @@ -49,9 +50,9 @@

r/{{ post.community }} - - {% if post.author_flair.flair_parts.len() > 0 %} - {% call utils::render_flair(post.author_flair.flair_parts) %} + + {% if post.author.flair.flair_parts.len() > 0 %} + {% call utils::render_flair(post.author.flair.flair_parts) %} {% endif %} {{ post.rel_time }} diff --git a/templates/search.html b/templates/search.html index 5355732..0bd9791 100644 --- a/templates/search.html +++ b/templates/search.html @@ -48,9 +48,9 @@

r/{{ post.community }} - - {% if post.author_flair.flair_parts.len() > 0 %} - {% call utils::render_flair(post.author_flair.flair_parts) %} + + {% if post.author.flair.flair_parts.len() > 0 %} + {% call utils::render_flair(post.author.flair.flair_parts) %} {% endif %} {{ post.rel_time }} diff --git a/templates/subreddit.html b/templates/subreddit.html index fbc1899..f0d2730 100644 --- a/templates/subreddit.html +++ b/templates/subreddit.html @@ -42,7 +42,7 @@

r/{{ post.community }} - + {{ post.rel_time }}

diff --git a/templates/user.html b/templates/user.html index a249df1..6b1111d 100644 --- a/templates/user.html +++ b/templates/user.html @@ -32,8 +32,8 @@

r/{{ post.community }} - {% if post.author_flair.flair_parts.len() > 0 %} - {% call utils::render_flair(post.author_flair.flair_parts) %} + {% if post.author.flair.flair_parts.len() > 0 %} + {% call utils::render_flair(post.author.flair.flair_parts) %} {% endif %} {{ post.rel_time }}