Moderator and admin distinguishers
This commit is contained in:
parent
6d5fd1dbf6
commit
a0bc1732cf
7 changed files with 69 additions and 51 deletions
46
src/post.rs
46
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<Comment> {
|
|||
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"),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
|
34
src/utils.rs
34
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<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,
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
--accent: aqua;
|
||||
--green: #5cff85;
|
||||
--nsfw: #FF5C5D;
|
||||
--admin: #ea0027;
|
||||
--text: white;
|
||||
--foreground: #222;
|
||||
--background: #0F0F0F;
|
||||
|
@ -603,11 +604,6 @@ a.search_subreddit:hover {
|
|||
.comment_link { text-decoration: underline; }
|
||||
.comment_author { opacity: 0.9; }
|
||||
|
||||
.comment_author.op {
|
||||
color: var(--accent);
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.author_flair {
|
||||
background: var(--highlighted);
|
||||
color: var(--text);
|
||||
|
@ -686,6 +682,13 @@ a.search_subreddit:hover {
|
|||
background: var(--foreground);
|
||||
}
|
||||
|
||||
.moderator, .admin { opacity: 1; }
|
||||
.op, .moderator, .admin { font-weight: bold; }
|
||||
|
||||
.op { color: var(--accent); }
|
||||
.moderator { color: var(--green); }
|
||||
.admin { color: var(--admin); }
|
||||
|
||||
/* Layouts */
|
||||
|
||||
.compact .post:not(.highlighted) {
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
{% block root %}/r/{{ post.community }}{% endblock %}{% block location %}r/{{ post.community }}{% endblock %}
|
||||
{% block head %}
|
||||
{% call super() %}
|
||||
<meta name="author" content="u/{{ post.author }}">
|
||||
<meta name="author" content="u/{{ post.author.name }}">
|
||||
{% endblock %}
|
||||
|
||||
<!-- OPEN COMMENT MACRO -->
|
||||
|
@ -21,9 +21,10 @@
|
|||
<div class="line"></div>
|
||||
</div>
|
||||
<details class="comment_right" open>
|
||||
<summary class="comment_data"><a class="comment_author {% if item.author == post.author %}op{% endif %}" href="/u/{{ item.author }}">u/{{ item.author }}</a>
|
||||
{% if item.flair.flair_parts.len() > 0 %}
|
||||
<small class="author_flair">{% call utils::render_flair(item.flair.flair_parts) %}</small>
|
||||
<summary class="comment_data">
|
||||
<a class="comment_author {{ item.author.distinguished }} {% if item.author.name == post.author.name %}op{% endif %}" href="/u/{{ item.author.name }}">u/{{ item.author.name }}</a>
|
||||
{% if item.author.flair.flair_parts.len() > 0 %}
|
||||
<small class="author_flair">{% call utils::render_flair(item.author.flair.flair_parts) %}</small>
|
||||
{% endif %}
|
||||
<span class="created" title="{{ post.created }}">{{ item.rel_time }}</span>
|
||||
</summary>
|
||||
|
@ -49,9 +50,9 @@
|
|||
<p class="post_header">
|
||||
<a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a>
|
||||
<span class="dot">•</span>
|
||||
<a class="post_author" href="/u/{{ post.author }}">u/{{ post.author }}</a>
|
||||
{% if post.author_flair.flair_parts.len() > 0 %}
|
||||
<small class="author_flair">{% call utils::render_flair(post.author_flair.flair_parts) %}</small>
|
||||
<a class="post_author" href="/u/{{ post.author.name }}">u/{{ post.author.name }}</a>
|
||||
{% if post.author.flair.flair_parts.len() > 0 %}
|
||||
<small class="author_flair">{% call utils::render_flair(post.author.flair.flair_parts) %}</small>
|
||||
{% endif %}
|
||||
<span class="dot">•</span>
|
||||
<span class="created" title="{{ post.created }}">{{ post.rel_time }}</span>
|
||||
|
|
|
@ -48,9 +48,9 @@
|
|||
<p class="post_header">
|
||||
<a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a>
|
||||
<span class="dot">•</span>
|
||||
<a class="post_author" href="/u/{{ post.author }}">u/{{ post.author }}</a>
|
||||
{% if post.author_flair.flair_parts.len() > 0 %}
|
||||
<small class="author_flair">{% call utils::render_flair(post.author_flair.flair_parts) %}</small>
|
||||
<a class="post_author" href="/u/{{ post.author.name }}">u/{{ post.author.name }}</a>
|
||||
{% if post.author.flair.flair_parts.len() > 0 %}
|
||||
<small class="author_flair">{% call utils::render_flair(post.author.flair.flair_parts) %}</small>
|
||||
{% endif %}
|
||||
<span class="dot">•</span>
|
||||
<span class="created" title="{{ post.created }}">{{ post.rel_time }}</span>
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
<p class="post_header">
|
||||
<a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a>
|
||||
<span class="dot">•</span>
|
||||
<a class="post_author" href="/u/{{ post.author }}">u/{{ post.author }}</a>
|
||||
<a class="post_author" href="/u/{{ post.author.name }}">u/{{ post.author.name }}</a>
|
||||
<span class="dot">•</span>
|
||||
<span class="created" title="{{ post.created }}">{{ post.rel_time }}</span>
|
||||
</p>
|
||||
|
|
|
@ -32,8 +32,8 @@
|
|||
<div class="post_text">
|
||||
<p class="post_header">
|
||||
<a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a>
|
||||
{% if post.author_flair.flair_parts.len() > 0 %}
|
||||
<small class="author_flair">{% call utils::render_flair(post.author_flair.flair_parts) %}</small>
|
||||
{% if post.author.flair.flair_parts.len() > 0 %}
|
||||
<small class="author_flair">{% call utils::render_flair(post.author.flair.flair_parts) %}</small>
|
||||
{% endif %}
|
||||
<span class="dot">•</span>
|
||||
<span class="created" title="{{ post.created }}">{{ post.rel_time }}</span>
|
||||
|
|
Loading…
Reference in a new issue