summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-04-28 19:28:52 +0200
committerMatthias Beyer <mail@beyermatthias.de>2020-04-28 20:26:27 +0200
commit98c328fffd7202d4819a2bb9f734ef63d1b8f38d (patch)
tree47d81aeb3326d26183a2fc67bf3748d7be761c4b
parentc665eeaafa170a3bdcec21c606a96a2cfc0dff47 (diff)
Rewrite state.rs to app.rs
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--src/app.rs40
-rw-r--r--src/main.rs2
-rw-r--r--src/state.rs26
3 files changed, 41 insertions, 27 deletions
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<Self, Error> {
+ Repository::new(host, port).map(|repo| App { repo, profile, publishing_key })
+ }
+
+ pub async fn new_profile(repo: Repository, names: Vec<String>) -> Result<Self> {
+ 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<IPFSKeyName, Data>);
-
-#[derive(Serialize, Deserialize, Debug, Hash, PartialEq, Eq)]
-pub struct IPFSKeyName(String);
-
-#[derive(Serialize, Deserialize, Debug)]
-pub struct Data {
- profile_cache: Vec<ProfileData>,
- connect_nodes: Vec<IPFSHash>, // TODO: stronger type?
-}
-
-#[derive(Serialize, Deserialize, Debug)]
-pub struct ProfileData {
- names: Vec<IPNSHash>,
- follow: bool,
- block: bool,
- knownnames: Vec<String>,
-}
-