diff options
author | Vika <vika@fireburn.ru> | 2024-08-26 14:08:07 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2024-08-26 14:36:57 +0300 |
commit | c79e950ca22c7a957c11e510700664327b042115 (patch) | |
tree | 1387e5931dd08cea0d21b2770964e169d7043905 /src/micropub | |
parent | 1a4a9b85b9bf9ae8650a2cd68416476c7d1770b3 (diff) | |
download | kittybox-c79e950ca22c7a957c11e510700664327b042115.tar.zst |
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.
Diffstat (limited to 'src/micropub')
-rw-r--r-- | src/micropub/mod.rs | 27 |
1 files changed, 7 insertions, 20 deletions
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<D: 'static + Storage>( 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<D: 'static + Storage>( 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<D: 'static + Storage>( .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<D: Storage, A: AuthBackend>( } // 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<MicropubChannel> = match db.get_channels(&user.me).await { @@ -645,7 +632,7 @@ pub(crate) async fn query<D: Storage, A: AuthBackend>( 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", |