Moderator and admin distinguishers

This commit is contained in:
spikecodes 2021-01-16 15:02:24 -08:00
parent 6d5fd1dbf6
commit a0bc1732cf
7 changed files with 69 additions and 51 deletions

View file

@ -13,6 +13,7 @@ use url::Url;
//
// STRUCTS
//
// Post flair with content, background color and foreground color
pub struct Flair {
pub flair_parts: Vec<FlairPart>,
@ -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<Post
title: if title.is_empty() { fallback_title.to_owned() } else { title },
community: val(post, "subreddit"),
body: rewrite_url(&val(post, "body_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"),
},
score: format_num(score),
upvote_ratio: ratio as i64,