about summary refs log tree commit diff
path: root/src/database/memory.rs
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2022-03-06 17:14:10 +0300
committerVika <vika@fireburn.ru>2022-03-06 17:14:10 +0300
commit998ffd3e3ac85a38aec8fc15c7addd02fa1af9ae (patch)
tree863e7daabf52edc8448fba45fc0b3e6acdba2b0a /src/database/memory.rs
parent11a39e85f2673029c7e317c02ae56bd8813773ad (diff)
Restored most of the functionality (except onboarding and some queries)
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 {