From c79e950ca22c7a957c11e510700664327b042115 Mon Sep 17 00:00:00 2001 From: Vika Date: Mon, 26 Aug 2024 14:08:07 +0300 Subject: Appease most clippy warnings The warnings only remain in places where I need them to remain, because I either need a reminder to implement something, or I need to refactor and simplify the code in question. --- src/micropub/mod.rs | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'src/micropub') diff --git a/src/micropub/mod.rs b/src/micropub/mod.rs index 65519e4..08150d2 100644 --- a/src/micropub/mod.rs +++ b/src/micropub/mod.rs @@ -67,7 +67,7 @@ fn populate_reply_context( if item.is_object() && (i != &item) { if let Some(props) = item["properties"].as_object_mut() { // Fixup the item: if it lacks a URL, add one. - if !props.get("url").and_then(serde_json::Value::as_array).map(|a| a.len() > 0).unwrap_or(false) { + if !props.get("url").and_then(serde_json::Value::as_array).map(|a| !a.is_empty()).unwrap_or(false) { props.insert("url".to_owned(), json!([i.as_str()])); } } @@ -191,9 +191,9 @@ async fn background_processing( tokio_stream::iter( post_contexts .into_iter() - .filter(|(url, ctx)| ctx.webmention.is_some()), + .filter(|(_url, ctx)| ctx.webmention.is_some()), ) - .for_each_concurrent(2, |(url, ctx)| async move { + .for_each_concurrent(2, |(_url, ctx)| async move { let mut map = std::collections::HashMap::new(); map.insert("source", uid); map.insert("target", ctx.url.as_str()); @@ -274,13 +274,6 @@ pub(crate) async fn _post( error_description: "UID clash was detected, operation aborted.".to_owned(), }); } - let user_domain = format!( - "{}{}", - user.me.host_str().unwrap(), - user.me.port() - .map(|port| format!(":{}", port)) - .unwrap_or_default() - ); // Save the post tracing::debug!("Saving post to database..."); db.put_post(&mf2, &user.me).await?; @@ -303,7 +296,7 @@ pub(crate) async fn _post( .unwrap() .to_string(); let food_channel = user.me.join(util::FOOD_CHANNEL_PATH).unwrap().to_string(); - let default_channels = vec![default_channel, vcards_channel, food_channel]; + let default_channels = [default_channel, vcards_channel, food_channel]; for chan in &mut channels { debug!("Adding post {} to channel {}", uid, chan); @@ -562,13 +555,7 @@ pub(crate) async fn query( } // TODO: consider replacing by `user.me.authority()`? - let user_domain = format!( - "{}{}", - user.me.host_str().unwrap(), - user.me.port() - .map(|port| format!(":{}", port)) - .unwrap_or_default() - ); + let user_domain = user.me.authority(); match query.q { QueryType::Config => { let channels: Vec = match db.get_channels(&user.me).await { @@ -645,7 +632,7 @@ pub(crate) async fn query( axum::response::Json(json!({ "syndicate-to": [] })).into_response() }, QueryType::Category => { - let categories = match db.categories(&user_domain).await { + let categories = match db.categories(user_domain).await { Ok(categories) => categories, Err(err) => { return MicropubError::new( @@ -844,7 +831,7 @@ mod tests { #[tokio::test] async fn test_query_foreign_url() { - let mut res = super::query( + let res = super::query( State(crate::database::MemoryStorage::default()), Some(axum::extract::Query(super::MicropubQuery::source( "https://aaronparecki.com/feeds/main", -- cgit 1.4.1