diff --git a/src/post.rs b/src/post.rs index 9f846b4..5edd023 100644 --- a/src/post.rs +++ b/src/post.rs @@ -1,5 +1,5 @@ // CRATES -use crate::utils::{format_num, format_url, request, val, Comment, ErrorTemplate, Flair, Params, Post}; +use crate::utils::{format_num, format_url, request, val, Comment, ErrorTemplate, Flair, Flags, Params, Post}; use actix_web::{http::StatusCode, web, HttpResponse, Result}; use async_recursion::async_recursion; @@ -130,7 +130,10 @@ async fn parse_post(json: serde_json::Value) -> Result { "white".to_string() }, ), - nsfw: post_data["data"]["over_18"].as_bool().unwrap_or(false), + flags: Flags { + nsfw: post_data["data"]["over_18"].as_bool().unwrap_or(false), + stickied: post_data["data"]["stickied"].as_bool().unwrap_or(false) + }, media: media.1, time: Utc.timestamp(unix_time, 0).format("%b %e %Y %H:%M UTC").to_string(), }; diff --git a/src/utils.rs b/src/utils.rs index 4d8a248..7737ff1 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -13,6 +13,11 @@ use base64::encode; // // Post flair with text, background color and foreground color pub struct Flair(pub String, pub String, pub String); +// Post flags with nsfw and stickied +pub struct Flags { + pub nsfw: bool, + pub stickied: bool +} // Post containing content, metadata and media pub struct Post { @@ -25,7 +30,7 @@ pub struct Post { pub score: String, pub post_type: String, pub flair: Flair, - pub nsfw: bool, + pub flags: Flags, pub media: String, pub time: String, } @@ -171,7 +176,10 @@ pub async fn fetch_posts(url: String, fallback_title: String) -> Result<(Vec

{{ post.score }}

- {% if post.nsfw %}
NSFW
{% endif %} + {% if post.flags.nsfw %}
NSFW
{% endif %}

diff --git a/templates/post.html b/templates/post.html index e8778fd..1242b61 100644 --- a/templates/post.html +++ b/templates/post.html @@ -28,7 +28,7 @@

{{ post.score }}

- {% if post.nsfw %}
NSFW
{% endif %} + {% if post.flags.nsfw %}
NSFW
{% endif %}

diff --git a/templates/subreddit.html b/templates/subreddit.html index f2c0117..b20886e 100644 --- a/templates/subreddit.html +++ b/templates/subreddit.html @@ -22,10 +22,10 @@ {% endif %} {% for post in posts %} -

+

{{ post.score }}

- {% if post.nsfw %}
NSFW
{% endif %} + {% if post.flags.nsfw %}
NSFW
{% endif %}

diff --git a/templates/user.html b/templates/user.html index a23dfec..842b391 100644 --- a/templates/user.html +++ b/templates/user.html @@ -22,7 +22,7 @@

{{ post.score }}

- {% if post.nsfw %}
NSFW
{% endif %} + {% if post.flags.nsfw %}
NSFW
{% endif %}