From f88e19c34d7c055b28835d84e0182b97163bb85b Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 28 Apr 2020 20:23:56 +0200 Subject: Fix App impl We need the device name and the publishing key to load an App object. For creating a new profile, we need the Repository instance and a publishing key as well as the names that shall be created. --- src/app.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/app.rs b/src/app.rs index 158b423..6a439c0 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,33 +1,39 @@ -use std::collections::HashMap; +use std::collections::BTreeMap; + +use failure::Error; use crate::types::util::IPFSHash; use crate::types::util::IPNSHash; +use crate::repository::repository::Repository; +use crate::types::content::Content; +use crate::types::content::Payload; +use crate::types::util::Timestamp; pub struct App { repo: Repository, - device_name: String, + device_name: IPNSHash, publishing_key: String } impl App { - pub fn load(device_name: String, publishing_key: String, host: &str, port: u16) -> Result { + pub fn load(device_name: IPNSHash, publishing_key: String, host: &str, port: u16) -> Result { Repository::new(host, port).map(|repo| App { repo, device_name, publishing_key }) } - pub async fn new_profile(repo: Repository, names: Vec) -> Result { + pub async fn new_profile(repo: Repository, publishing_key: &str, 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 timestamp = Timestamp::now(); + let content = Content::new(vec![], Some(timestamp), payload); - let head = repository.put_content(content).await?; - let device_name = repository.publish(&publishing_key, &head).await?; + let head = repo.put_content(content).await?; + let device_name = repo.publish(&publishing_key, &head).await?; - Ok(App { repository, device_name, publishing_key }) + Ok(App { repo, device_name, publishing_key: publishing_key.to_string() }) } -- cgit v1.2.3