about summary refs log tree commit diff
path: root/src/micropub
diff options
context:
space:
mode:
Diffstat (limited to 'src/micropub')
-rw-r--r--src/micropub/mod.rs27
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",