Disable dysfunctional moderator list feature

This commit is contained in:
spikecodes 2021-06-11 11:03:36 -07:00
parent f84f4c0326
commit d2002c9027
No known key found for this signature in database
GPG key ID: 004CECFF9B463BCB
8 changed files with 76 additions and 95 deletions

View file

@ -1,7 +1,7 @@
// Global specifiers
#![forbid(unsafe_code)]
#![warn(clippy::pedantic, clippy::all)]
#![allow(clippy::needless_pass_by_value, clippy::cast_possible_truncation, clippy::cast_possible_wrap, clippy::find_map)]
#![allow(clippy::needless_pass_by_value, clippy::cast_possible_truncation, clippy::cast_possible_wrap, clippy::manual_find_map)]
// Reference local files
mod post;

View file

@ -53,7 +53,7 @@ pub trait ResponseExt {
impl RequestExt for Request<Body> {
fn params(&self) -> Params {
self.extensions().get::<Params>().unwrap_or(&Params::new()).to_owned()
self.extensions().get::<Params>().unwrap_or(&Params::new()).clone()
// self.extensions()
// .get::<RequestMeta>()
// .and_then(|meta| meta.route_params())
@ -171,7 +171,7 @@ impl Server {
// If a route was configured for this path
Ok(found) => {
let mut parammed = req;
parammed.set_params(found.params().to_owned());
parammed.set_params(found.params().clone());
// Run the route's function
let func = (found.handler().to_owned().to_owned())(parammed);

View file

@ -67,7 +67,7 @@ pub async fn set(req: Request<Body>) -> Result<Response<Body>, String> {
for &name in &PREFS {
match form.get(name) {
Some(value) => response.insert_cookie(
Cookie::build(name.to_owned(), value.to_owned())
Cookie::build(name.to_owned(), value.clone())
.path("/")
.http_only(true)
.expires(OffsetDateTime::now_utc() + Duration::weeks(52))
@ -106,7 +106,7 @@ fn set_cookies_method(req: Request<Body>, remove_cookies: bool) -> Response<Body
for name in [PREFS.to_vec(), vec!["subscriptions"]].concat() {
match form.get(name) {
Some(value) => response.insert_cookie(
Cookie::build(name.to_owned(), value.to_owned())
Cookie::build(name.to_owned(), value.clone())
.path("/")
.http_only(true)
.expires(OffsetDateTime::now_utc() + Duration::weeks(52))

View file

@ -51,10 +51,10 @@ pub async fn community(req: Request<Body>) -> Result<Response<Body>, String> {
if subscribed.is_empty() {
"popular".to_string()
} else {
subscribed.to_owned()
subscribed.clone()
}
} else {
front_page.to_owned()
front_page.clone()
});
let quarantined = can_access_quarantine(&req, &sub) || root;
@ -273,11 +273,12 @@ pub async fn sidebar(req: Request<Body>) -> Result<Response<Body>, String> {
match json(path, quarantined).await {
// If success, receive JSON in response
Ok(response) => template(WikiTemplate {
wiki: format!(
"{}<hr><h1>Moderators</h1><br><ul>{}</ul>",
rewrite_urls(&val(&response, "description_html").replace("\\", "")),
moderators(&sub, quarantined).await?.join(""),
),
wiki: rewrite_urls(&val(&response, "description_html").replace("\\", "")),
// wiki: format!(
// "{}<hr><h1>Moderators</h1><br><ul>{}</ul>",
// rewrite_urls(&val(&response, "description_html").replace("\\", "")),
// moderators(&sub, quarantined).await.unwrap_or(vec!["Could not fetch moderators".to_string()]).join(""),
// ),
sub,
page: "Sidebar".to_string(),
prefs: Preferences::new(req),
@ -292,39 +293,39 @@ pub async fn sidebar(req: Request<Body>) -> Result<Response<Body>, String> {
}
}
pub async fn moderators(sub: &str, quarantined: bool) -> Result<Vec<String>, String> {
// Retrieve and format the html for the moderators list
Ok(
moderators_list(sub, quarantined)
.await?
.iter()
.map(|m| format!("<li><a style=\"color: var(--accent)\" href=\"/u/{name}\">{name}</a></li>", name = m))
.collect(),
)
}
// pub async fn moderators(sub: &str, quarantined: bool) -> Result<Vec<String>, String> {
// // Retrieve and format the html for the moderators list
// Ok(
// moderators_list(sub, quarantined)
// .await?
// .iter()
// .map(|m| format!("<li><a style=\"color: var(--accent)\" href=\"/u/{name}\">{name}</a></li>", name = m))
// .collect(),
// )
// }
async fn moderators_list(sub: &str, quarantined: bool) -> Result<Vec<String>, String> {
// Build the moderator list URL
let path: String = format!("/r/{}/about/moderators.json?raw_json=1", sub);
// async fn moderators_list(sub: &str, quarantined: bool) -> Result<Vec<String>, String> {
// // Build the moderator list URL
// let path: String = format!("/r/{}/about/moderators.json?raw_json=1", sub);
// Retrieve response
json(path, quarantined).await.map(|response| {
// Traverse json tree and format into list of strings
response["data"]["children"]
.as_array()
.unwrap_or(&Vec::new())
.iter()
.filter_map(|moderator| {
let name = moderator["name"].as_str().unwrap_or_default();
if name.is_empty() {
None
} else {
Some(name.to_string())
}
})
.collect::<Vec<_>>()
})
}
// // Retrieve response
// json(path, quarantined).await.map(|response| {
// // Traverse json tree and format into list of strings
// response["data"]["children"]
// .as_array()
// .unwrap_or(&Vec::new())
// .iter()
// .filter_map(|moderator| {
// let name = moderator["name"].as_str().unwrap_or_default();
// if name.is_empty() {
// None
// } else {
// Some(name.to_string())
// }
// })
// .collect::<Vec<_>>()
// })
// }
// SUBREDDIT
async fn subreddit(sub: &str, quarantined: bool) -> Result<Subreddit, String> {
@ -347,7 +348,7 @@ async fn subreddit(sub: &str, quarantined: bool) -> Result<Subreddit, String> {
title: esc!(&res, "title"),
description: esc!(&res, "public_description"),
info: rewrite_urls(&val(&res, "description_html").replace("\\", "")),
moderators: moderators_list(sub, quarantined).await?,
// moderators: moderators_list(sub, quarantined).await.unwrap_or_default(),
icon: format_url(&icon),
members: format_num(members),
active: format_num(active),

View file

@ -253,7 +253,7 @@ impl Post {
posts.push(Self {
id: val(post, "id"),
title: esc!(if title.is_empty() { fallback_title.to_owned() } else { title }),
title: esc!(if title.is_empty() { fallback_title.clone() } else { title }),
community: val(post, "subreddit"),
body: rewrite_urls(&val(post, "body_html")),
author: Author {
@ -362,7 +362,7 @@ pub struct Subreddit {
pub title: String,
pub description: String,
pub info: String,
pub moderators: Vec<String>,
// pub moderators: Vec<String>,
pub icon: String,
pub members: (String, String),
pub active: (String, String),
@ -424,7 +424,7 @@ pub fn param(path: &str, value: &str) -> Option<String> {
.into_owned()
.collect::<HashMap<_, _>>()
.get(value)?
.to_owned(),
.clone(),
)
}