From 998ffd3e3ac85a38aec8fc15c7addd02fa1af9ae Mon Sep 17 00:00:00 2001 From: Vika Date: Sun, 6 Mar 2022 17:14:10 +0300 Subject: Restored most of the functionality (except onboarding and some queries) --- src/database/memory.rs | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'src/database/memory.rs') 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| { - 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::>()).await.into_iter().filter_map(|chan| chan).collect::>()), + ).collect::>()).await.into_iter().flatten().collect::>()), None => Ok(vec![]) } } + #[allow(unused_variables)] async fn read_feed_with_limit(&self, url: &'_ str, after: &'_ Option, limit: usize, user: &'_ Option) -> Result> { todo!() } @@ -177,15 +176,23 @@ impl Storage for MemoryStorage { Ok(()) } + #[allow(unused_variables)] async fn get_setting(&self, setting: &'_ str, user: &'_ str) -> Result { 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 { -- cgit 1.4.1