about summary refs log tree commit diff
path: root/src/database/memory.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/database/memory.rs')
-rw-r--r--src/database/memory.rs29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/database/memory.rs b/src/database/memory.rs
index c83bc8c..df142d3 100644
--- a/src/database/memory.rs
+++ b/src/database/memory.rs
@@ -1,3 +1,4 @@
+#![allow(clippy::todo)]
 use async_trait::async_trait;
 use std::collections::HashMap;
 use std::sync::Arc;
@@ -6,7 +7,6 @@ use futures_util::FutureExt;
 use serde_json::json;
 
 use crate::database::{Storage, Result, StorageError, ErrorKind, MicropubChannel};
-use crate::indieauth::User;
 
 #[derive(Clone, Debug)]
 pub struct MemoryStorage {
@@ -41,7 +41,7 @@ impl Storage for MemoryStorage {
         }
     }
 
-    async fn put_post(&self, post: &'_ serde_json::Value, user: &'_ str) -> Result<()> {
+    async fn put_post(&self, post: &'_ serde_json::Value, _user: &'_ str) -> Result<()> {
         let mapping = &mut self.mapping.write().await;
         let key: &str;
         match post["properties"]["uid"][0].as_str() {
@@ -51,7 +51,7 @@ impl Storage for MemoryStorage {
         mapping.insert(key.to_string(), post.clone());
         if post["properties"]["url"].is_array() {
             for url in post["properties"]["url"].as_array().unwrap().iter().map(|i| i.as_str().unwrap().to_string()) {
-                if &url != key {
+                if url != key {
                     mapping.insert(url, json!({"see_other": key}));
                 }
             }
@@ -59,7 +59,7 @@ impl Storage for MemoryStorage {
         if post["type"].as_array().unwrap().iter().any(|i| i == "h-feed") {
             // This is a feed. Add it to the channels array if it's not already there.
             println!("{:#}", post);
-            self.channels.write().await.entry(post["properties"]["author"][0].as_str().unwrap().to_string()).or_insert(vec![]).push(key.to_string())
+            self.channels.write().await.entry(post["properties"]["author"][0].as_str().unwrap().to_string()).or_insert_with(Vec::new).push(key.to_string())
         }
         Ok(())
     }
@@ -155,19 +155,18 @@ impl Storage for MemoryStorage {
                 .map(|channel| self.get_post(channel)
                     .map(|result| result.unwrap())
                     .map(|post: Option<serde_json::Value>| {
-                        if let Some(post) = post {
-                            Some(MicropubChannel {
-                                uid: post["properties"]["uid"][0].as_str().unwrap().to_string(),
-                                name: post["properties"]["name"][0].as_str().unwrap().to_string()
-                            })
-                        } else { None }
+                        post.map(|post| MicropubChannel {
+                            uid: post["properties"]["uid"][0].as_str().unwrap().to_string(),
+                            name: post["properties"]["name"][0].as_str().unwrap().to_string()
+                        })
                     })
-                ).collect::<Vec<_>>()).await.into_iter().filter_map(|chan| chan).collect::<Vec<_>>()),
+                ).collect::<Vec<_>>()).await.into_iter().flatten().collect::<Vec<_>>()),
             None => Ok(vec![])
         }
         
     }
 
+    #[allow(unused_variables)]
     async fn read_feed_with_limit(&self, url: &'_ str, after: &'_ Option<String>, limit: usize, user: &'_ Option<String>) -> Result<Option<serde_json::Value>> {
         todo!()
     }
@@ -177,15 +176,23 @@ impl Storage for MemoryStorage {
         Ok(())
     }
 
+    #[allow(unused_variables)]
     async fn get_setting(&self, setting: &'_ str, user: &'_ str) -> Result<String> {
         todo!()
     }
 
+    #[allow(unused_variables)]
     async fn set_setting(&self, setting: &'_ str, user: &'_ str, value: &'_ str) -> Result<()> {
         todo!()
     }
 }
 
+impl Default for MemoryStorage {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl MemoryStorage {
     pub fn new() -> Self {
         Self {