From 98c328fffd7202d4819a2bb9f734ef63d1b8f38d Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 28 Apr 2020 19:28:52 +0200 Subject: Rewrite state.rs to app.rs Signed-off-by: Matthias Beyer --- src/app.rs | 40 ++++++++++++++++++++++++++++++++++++++++ src/main.rs | 2 +- src/state.rs | 26 -------------------------- 3 files changed, 41 insertions(+), 27 deletions(-) create mode 100644 src/app.rs delete mode 100644 src/state.rs diff --git a/src/app.rs b/src/app.rs new file mode 100644 index 0000000..8477378 --- /dev/null +++ b/src/app.rs @@ -0,0 +1,40 @@ +use std::collections::HashMap; + +use crate::types::util::IPFSHash; +use crate::types::util::IPNSHash; + +pub struct App { + repo: Repository, + profile: Profile, + publishing_key: String +} + +impl App { + + pub fn load(profile: Profile, publishing_key: String, host: &str, port: u16) -> Result { + Repository::new(host, port).map(|repo| App { repo, profile, publishing_key }) + } + + pub async fn new_profile(repo: Repository, names: Vec) -> Result { + let payload = Payload::Profile { + names, + picture: None, + more: BTreeMap::new(), + }; + let timestamp = types::Timestamp::now(); + let content = Content::new(vec![], timestame, payload); + + let head = repository.put_content(content).await?; + let device_name = repository.publish(&publishing_key, &head).await?; + + let profile = Profile { + device_name, + devices: vec![], + }; + + Ok(App { repository, profile, publishing_key }) + } + + +} + diff --git a/src/main.rs b/src/main.rs index 0f99ca3..5380c9d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,10 +21,10 @@ extern crate itertools; #[macro_use] extern crate tokio; #[macro_use] extern crate add_getters_setters; +mod app; mod cli_ui; mod configuration; mod repository; -mod state; mod typeext; mod types; mod version; diff --git a/src/state.rs b/src/state.rs deleted file mode 100644 index 46661b1..0000000 --- a/src/state.rs +++ /dev/null @@ -1,26 +0,0 @@ -use std::collections::HashMap; - -use crate::types::util::IPFSHash; -use crate::types::util::IPNSHash; - -/// TODO: Use rustbreak for persistence layer -#[derive(Serialize, Deserialize, Debug)] -pub struct AppState(HashMap); - -#[derive(Serialize, Deserialize, Debug, Hash, PartialEq, Eq)] -pub struct IPFSKeyName(String); - -#[derive(Serialize, Deserialize, Debug)] -pub struct Data { - profile_cache: Vec, - connect_nodes: Vec, // TODO: stronger type? -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct ProfileData { - names: Vec, - follow: bool, - block: bool, - knownnames: Vec, -} - -- cgit v1.2.3