summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-04-28 20:23:56 +0200
committerMatthias Beyer <mail@beyermatthias.de>2020-04-28 20:28:49 +0200
commitf88e19c34d7c055b28835d84e0182b97163bb85b (patch)
treeab588e3cfe543af71a75bab43ab9b8c56669d0c4
parent59b633d23ae0b4b9b7789ac79c00faabf1f728bd (diff)
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.
-rw-r--r--src/app.rs24
1 files 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<Self, Error> {
+ pub fn load(device_name: IPNSHash, publishing_key: String, host: &str, port: u16) -> Result<Self, Error> {
Repository::new(host, port).map(|repo| App { repo, device_name, publishing_key })
}
- pub async fn new_profile(repo: Repository, names: Vec<String>) -> Result<Self> {
+ pub async fn new_profile(repo: Repository, publishing_key: &str, names: Vec<String>) -> Result<Self, Error> {
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() })
}