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.rs23
1 files changed, 9 insertions, 14 deletions
diff --git a/src/database/memory.rs b/src/database/memory.rs
index 564f451..56caeec 100644
--- a/src/database/memory.rs
+++ b/src/database/memory.rs
@@ -11,7 +11,7 @@ use crate::database::{ErrorKind, MicropubChannel, Result, settings, Storage, Sto
 #[derive(Clone, Debug)]
 pub struct MemoryStorage {
     pub mapping: Arc<RwLock<HashMap<String, serde_json::Value>>>,
-    pub channels: Arc<RwLock<HashMap<String, Vec<String>>>>,
+    pub channels: Arc<RwLock<HashMap<url::Url, Vec<String>>>>,
 }
 
 #[async_trait]
@@ -45,7 +45,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: &url::Url) -> Result<()> {
         let mapping = &mut self.mapping.write().await;
         let key: &str = match post["properties"]["uid"][0].as_str() {
             Some(uid) => uid,
@@ -80,12 +80,7 @@ impl Storage for MemoryStorage {
             self.channels
                 .write()
                 .await
-                .entry(
-                    post["properties"]["author"][0]
-                        .as_str()
-                        .unwrap()
-                        .to_string(),
-                )
+                .entry(user.clone())
                 .or_insert_with(Vec::new)
                 .push(key.to_string())
         }
@@ -165,7 +160,7 @@ impl Storage for MemoryStorage {
         Ok(())
     }
 
-    async fn get_channels(&self, user: &'_ str) -> Result<Vec<MicropubChannel>> {
+    async fn get_channels(&self, user: &url::Url) -> Result<Vec<MicropubChannel>> {
         match self.channels.read().await.get(user) {
             Some(channels) => Ok(futures_util::future::join_all(
                 channels
@@ -197,9 +192,9 @@ impl Storage for MemoryStorage {
     async fn read_feed_with_limit(
         &self,
         url: &'_ str,
-        after: &'_ Option<String>,
+        after: Option<&str>,
         limit: usize,
-        user: &'_ Option<String>,
+        user: Option<&url::Url>,
     ) -> Result<Option<serde_json::Value>> {
         todo!()
     }
@@ -210,7 +205,7 @@ impl Storage for MemoryStorage {
         url: &'_ str,
         cursor: Option<&'_ str>,
         limit: usize,
-        user: Option<&'_ str>
+        user: Option<&url::Url>
     ) -> Result<Option<(serde_json::Value, Option<String>)>> {
         todo!()
     }
@@ -221,12 +216,12 @@ impl Storage for MemoryStorage {
     }
 
     #[allow(unused_variables)]
-    async fn get_setting<S: settings::Setting<'a>, 'a>(&'_ self, user: &'_ str) -> Result<S> {
+    async fn get_setting<S: settings::Setting<'a>, 'a>(&'_ self, user: &url::Url) -> Result<S> {
         todo!()
     }
 
     #[allow(unused_variables)]
-    async fn set_setting<S: settings::Setting<'a> + 'a, 'a>(&self, user: &'a str, value: S::Data) -> Result<()> {
+    async fn set_setting<S: settings::Setting<'a> + 'a, 'a>(&self, user: &'a url::Url, value: S::Data) -> Result<()> {
         todo!()
     }