Moderator and admin distinguishers
This commit is contained in:
parent
6d5fd1dbf6
commit
a0bc1732cf
22
src/post.rs
22
src/post.rs
@ -1,5 +1,5 @@
|
|||||||
// CRATES
|
// 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 actix_web::{HttpRequest, HttpResponse};
|
||||||
|
|
||||||
use async_recursion::async_recursion;
|
use async_recursion::async_recursion;
|
||||||
@ -80,8 +80,9 @@ async fn parse_post(json: &serde_json::Value) -> Post {
|
|||||||
title: val(post, "title"),
|
title: val(post, "title"),
|
||||||
community: val(post, "subreddit"),
|
community: val(post, "subreddit"),
|
||||||
body: rewrite_url(&val(post, "selftext_html")),
|
body: rewrite_url(&val(post, "selftext_html")),
|
||||||
author: val(post, "author"),
|
author: Author {
|
||||||
author_flair: Flair {
|
name: val(post, "author"),
|
||||||
|
flair: Flair {
|
||||||
flair_parts: parse_rich_flair(
|
flair_parts: parse_rich_flair(
|
||||||
val(post, "author_flair_type"),
|
val(post, "author_flair_type"),
|
||||||
post["data"]["author_flair_richtext"].as_array(),
|
post["data"]["author_flair_richtext"].as_array(),
|
||||||
@ -90,6 +91,8 @@ async fn parse_post(json: &serde_json::Value) -> Post {
|
|||||||
background_color: val(post, "author_flair_background_color"),
|
background_color: val(post, "author_flair_background_color"),
|
||||||
foreground_color: val(post, "author_flair_text_color"),
|
foreground_color: val(post, "author_flair_text_color"),
|
||||||
},
|
},
|
||||||
|
distinguished: val(post, "distinguished"),
|
||||||
|
},
|
||||||
permalink: val(post, "permalink"),
|
permalink: val(post, "permalink"),
|
||||||
score: format_num(score),
|
score: format_num(score),
|
||||||
upvote_ratio: ratio as i64,
|
upvote_ratio: ratio as i64,
|
||||||
@ -150,11 +153,8 @@ async fn parse_comments(json: &serde_json::Value) -> Vec<Comment> {
|
|||||||
comments.push(Comment {
|
comments.push(Comment {
|
||||||
id: val(&comment, "id"),
|
id: val(&comment, "id"),
|
||||||
body,
|
body,
|
||||||
author: val(&comment, "author"),
|
author: Author {
|
||||||
score: format_num(score),
|
name: val(&comment, "author"),
|
||||||
rel_time,
|
|
||||||
created,
|
|
||||||
replies,
|
|
||||||
flair: Flair {
|
flair: Flair {
|
||||||
flair_parts: parse_rich_flair(
|
flair_parts: parse_rich_flair(
|
||||||
val(&comment, "author_flair_type"),
|
val(&comment, "author_flair_type"),
|
||||||
@ -164,6 +164,12 @@ async fn parse_comments(json: &serde_json::Value) -> Vec<Comment> {
|
|||||||
background_color: val(&comment, "author_flair_background_color"),
|
background_color: val(&comment, "author_flair_background_color"),
|
||||||
foreground_color: val(&comment, "author_flair_text_color"),
|
foreground_color: val(&comment, "author_flair_text_color"),
|
||||||
},
|
},
|
||||||
|
distinguished: val(&comment, "distinguished"),
|
||||||
|
},
|
||||||
|
score: format_num(score),
|
||||||
|
rel_time,
|
||||||
|
created,
|
||||||
|
replies,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
20
src/utils.rs
20
src/utils.rs
@ -13,6 +13,7 @@ use url::Url;
|
|||||||
//
|
//
|
||||||
// STRUCTS
|
// STRUCTS
|
||||||
//
|
//
|
||||||
|
|
||||||
// Post flair with content, background color and foreground color
|
// Post flair with content, background color and foreground color
|
||||||
pub struct Flair {
|
pub struct Flair {
|
||||||
pub flair_parts: Vec<FlairPart>,
|
pub flair_parts: Vec<FlairPart>,
|
||||||
@ -26,6 +27,12 @@ pub struct FlairPart {
|
|||||||
pub value: String,
|
pub value: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct Author {
|
||||||
|
pub name: String,
|
||||||
|
pub flair: Flair,
|
||||||
|
pub distinguished: String,
|
||||||
|
}
|
||||||
|
|
||||||
// Post flags with nsfw and stickied
|
// Post flags with nsfw and stickied
|
||||||
pub struct Flags {
|
pub struct Flags {
|
||||||
pub nsfw: bool,
|
pub nsfw: bool,
|
||||||
@ -38,8 +45,7 @@ pub struct Post {
|
|||||||
pub title: String,
|
pub title: String,
|
||||||
pub community: String,
|
pub community: String,
|
||||||
pub body: String,
|
pub body: String,
|
||||||
pub author: String,
|
pub author: Author,
|
||||||
pub author_flair: Flair,
|
|
||||||
pub permalink: String,
|
pub permalink: String,
|
||||||
pub score: String,
|
pub score: String,
|
||||||
pub upvote_ratio: i64,
|
pub upvote_ratio: i64,
|
||||||
@ -57,8 +63,7 @@ pub struct Post {
|
|||||||
pub struct Comment {
|
pub struct Comment {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub body: String,
|
pub body: String,
|
||||||
pub author: String,
|
pub author: Author,
|
||||||
pub flair: Flair,
|
|
||||||
pub score: String,
|
pub score: String,
|
||||||
pub rel_time: String,
|
pub rel_time: String,
|
||||||
pub created: String,
|
pub created: String,
|
||||||
@ -308,8 +313,9 @@ pub async fn fetch_posts(path: &str, fallback_title: String) -> Result<(Vec<Post
|
|||||||
title: if title.is_empty() { fallback_title.to_owned() } else { title },
|
title: if title.is_empty() { fallback_title.to_owned() } else { title },
|
||||||
community: val(post, "subreddit"),
|
community: val(post, "subreddit"),
|
||||||
body: rewrite_url(&val(post, "body_html")),
|
body: rewrite_url(&val(post, "body_html")),
|
||||||
author: val(post, "author"),
|
author: Author {
|
||||||
author_flair: Flair {
|
name: val(post, "author"),
|
||||||
|
flair: Flair {
|
||||||
flair_parts: parse_rich_flair(
|
flair_parts: parse_rich_flair(
|
||||||
val(post, "author_flair_type"),
|
val(post, "author_flair_type"),
|
||||||
post["data"]["author_flair_richtext"].as_array(),
|
post["data"]["author_flair_richtext"].as_array(),
|
||||||
@ -318,6 +324,8 @@ pub async fn fetch_posts(path: &str, fallback_title: String) -> Result<(Vec<Post
|
|||||||
background_color: val(post, "author_flair_background_color"),
|
background_color: val(post, "author_flair_background_color"),
|
||||||
foreground_color: val(post, "author_flair_text_color"),
|
foreground_color: val(post, "author_flair_text_color"),
|
||||||
},
|
},
|
||||||
|
distinguished: val(post, "distinguished"),
|
||||||
|
},
|
||||||
score: format_num(score),
|
score: format_num(score),
|
||||||
upvote_ratio: ratio as i64,
|
upvote_ratio: ratio as i64,
|
||||||
post_type,
|
post_type,
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
--accent: aqua;
|
--accent: aqua;
|
||||||
--green: #5cff85;
|
--green: #5cff85;
|
||||||
--nsfw: #FF5C5D;
|
--nsfw: #FF5C5D;
|
||||||
|
--admin: #ea0027;
|
||||||
--text: white;
|
--text: white;
|
||||||
--foreground: #222;
|
--foreground: #222;
|
||||||
--background: #0F0F0F;
|
--background: #0F0F0F;
|
||||||
@ -603,11 +604,6 @@ a.search_subreddit:hover {
|
|||||||
.comment_link { text-decoration: underline; }
|
.comment_link { text-decoration: underline; }
|
||||||
.comment_author { opacity: 0.9; }
|
.comment_author { opacity: 0.9; }
|
||||||
|
|
||||||
.comment_author.op {
|
|
||||||
color: var(--accent);
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
.author_flair {
|
.author_flair {
|
||||||
background: var(--highlighted);
|
background: var(--highlighted);
|
||||||
color: var(--text);
|
color: var(--text);
|
||||||
@ -686,6 +682,13 @@ a.search_subreddit:hover {
|
|||||||
background: var(--foreground);
|
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 */
|
/* Layouts */
|
||||||
|
|
||||||
.compact .post:not(.highlighted) {
|
.compact .post:not(.highlighted) {
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
{% block root %}/r/{{ post.community }}{% endblock %}{% block location %}r/{{ post.community }}{% endblock %}
|
{% block root %}/r/{{ post.community }}{% endblock %}{% block location %}r/{{ post.community }}{% endblock %}
|
||||||
{% block head %}
|
{% block head %}
|
||||||
{% call super() %}
|
{% call super() %}
|
||||||
<meta name="author" content="u/{{ post.author }}">
|
<meta name="author" content="u/{{ post.author.name }}">
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
<!-- OPEN COMMENT MACRO -->
|
<!-- OPEN COMMENT MACRO -->
|
||||||
@ -21,9 +21,10 @@
|
|||||||
<div class="line"></div>
|
<div class="line"></div>
|
||||||
</div>
|
</div>
|
||||||
<details class="comment_right" open>
|
<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>
|
<summary class="comment_data">
|
||||||
{% if item.flair.flair_parts.len() > 0 %}
|
<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>
|
||||||
<small class="author_flair">{% call utils::render_flair(item.flair.flair_parts) %}</small>
|
{% if item.author.flair.flair_parts.len() > 0 %}
|
||||||
|
<small class="author_flair">{% call utils::render_flair(item.author.flair.flair_parts) %}</small>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<span class="created" title="{{ post.created }}">{{ item.rel_time }}</span>
|
<span class="created" title="{{ post.created }}">{{ item.rel_time }}</span>
|
||||||
</summary>
|
</summary>
|
||||||
@ -49,9 +50,9 @@
|
|||||||
<p class="post_header">
|
<p class="post_header">
|
||||||
<a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a>
|
<a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a>
|
||||||
<span class="dot">•</span>
|
<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>
|
||||||
{% if post.author_flair.flair_parts.len() > 0 %}
|
{% if post.author.flair.flair_parts.len() > 0 %}
|
||||||
<small class="author_flair">{% call utils::render_flair(post.author_flair.flair_parts) %}</small>
|
<small class="author_flair">{% call utils::render_flair(post.author.flair.flair_parts) %}</small>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<span class="dot">•</span>
|
<span class="dot">•</span>
|
||||||
<span class="created" title="{{ post.created }}">{{ post.rel_time }}</span>
|
<span class="created" title="{{ post.created }}">{{ post.rel_time }}</span>
|
||||||
|
@ -48,9 +48,9 @@
|
|||||||
<p class="post_header">
|
<p class="post_header">
|
||||||
<a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a>
|
<a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a>
|
||||||
<span class="dot">•</span>
|
<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>
|
||||||
{% if post.author_flair.flair_parts.len() > 0 %}
|
{% if post.author.flair.flair_parts.len() > 0 %}
|
||||||
<small class="author_flair">{% call utils::render_flair(post.author_flair.flair_parts) %}</small>
|
<small class="author_flair">{% call utils::render_flair(post.author.flair.flair_parts) %}</small>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<span class="dot">•</span>
|
<span class="dot">•</span>
|
||||||
<span class="created" title="{{ post.created }}">{{ post.rel_time }}</span>
|
<span class="created" title="{{ post.created }}">{{ post.rel_time }}</span>
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
<p class="post_header">
|
<p class="post_header">
|
||||||
<a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a>
|
<a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a>
|
||||||
<span class="dot">•</span>
|
<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="dot">•</span>
|
||||||
<span class="created" title="{{ post.created }}">{{ post.rel_time }}</span>
|
<span class="created" title="{{ post.created }}">{{ post.rel_time }}</span>
|
||||||
</p>
|
</p>
|
||||||
|
@ -32,8 +32,8 @@
|
|||||||
<div class="post_text">
|
<div class="post_text">
|
||||||
<p class="post_header">
|
<p class="post_header">
|
||||||
<a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a>
|
<a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a>
|
||||||
{% if post.author_flair.flair_parts.len() > 0 %}
|
{% if post.author.flair.flair_parts.len() > 0 %}
|
||||||
<small class="author_flair">{% call utils::render_flair(post.author_flair.flair_parts) %}</small>
|
<small class="author_flair">{% call utils::render_flair(post.author.flair.flair_parts) %}</small>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<span class="dot">•</span>
|
<span class="dot">•</span>
|
||||||
<span class="created" title="{{ post.created }}">{{ post.rel_time }}</span>
|
<span class="created" title="{{ post.created }}">{{ post.rel_time }}</span>
|
||||||
|
Loading…
Reference in New Issue
Block a user