Support displaying awards (#168)

* Initial implementation of award parsing

* Posts: Implement awards as part of post

* Posts: remove parse_awards dead code

* Posts: initial implementation of displaying Awards at the post title

* Posts: Proxy static award images

* Client: i.redd.it should take path as argument not ID

* Posts: Just like Reddit make award size 16px

* Templates: limit the awards to 4 awards to increase performance

* Comments: Make awards a property of comments and display them

* Format and correct /img/:id

* Update comment.html

* [Optimization] Awards is not longer async

* [Revert] Posts can now display more than 4 awards again

* [Implementation] Awards not display on the frontpage

* [Implementation] Display count on awards

* Post: Start working on awards css

* Awards: Move the image size to css

* Awards: Start implementing tooltips

* Refactor awards code and tweak CSS indentation

* Unify Awards::new and Awards::parse

* Use native tooltips and brighten awards background

Co-authored-by: Spike <19519553+spikecodes@users.noreply.github.com>
This commit is contained in:
Diego Magdaleno 2021-11-24 20:08:27 -06:00 committed by GitHub
parent 3054b9f4a0
commit bd413060c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 118 additions and 7 deletions

View file

@ -3,8 +3,9 @@ use crate::client::json;
use crate::esc;
use crate::server::RequestExt;
use crate::subreddit::{can_access_quarantine, quarantine};
use crate::utils::{error, format_num, format_url, param, rewrite_urls, setting, template, time, val, Author, Comment, Flags, Flair, FlairPart, Media, Post, Preferences};
use crate::utils::{
error, format_num, format_url, param, rewrite_urls, setting, template, time, val, Author, Awards, Comment, Flags, Flair, FlairPart, Media, Post, Preferences,
};
use hyper::{Body, Request, Response};
use askama::Template;
@ -93,6 +94,8 @@ async fn parse_post(json: &serde_json::Value) -> Post {
// Determine the type of media along with the media URL
let (post_type, media, gallery) = Media::parse(&post["data"]).await;
let awards: Awards = Awards::parse(&post["data"]["all_awardings"]);
// Build a post using data parsed from Reddit post API
Post {
id: val(post, "id"),
@ -148,6 +151,7 @@ async fn parse_post(json: &serde_json::Value) -> Post {
created,
comments: format_num(post["data"]["num_comments"].as_i64().unwrap_or_default()),
gallery,
awards,
}
}
@ -178,6 +182,8 @@ fn parse_comments(json: &serde_json::Value, post_link: &str, post_author: &str,
Vec::new()
};
let awards: Awards = Awards::parse(&data["all_awardings"]);
let parent_kind_and_id = val(&comment, "parent_id");
let parent_info = parent_kind_and_id.split('_').collect::<Vec<&str>>();
@ -224,6 +230,7 @@ fn parse_comments(json: &serde_json::Value, post_link: &str, post_author: &str,
edited,
replies,
highlighted,
awards,
collapsed,
}
})