summaryrefslogtreecommitdiffstats
path: root/src/app.rs
blob: 84773788cee02dfc53b8bcbb47a64796bf5fe520 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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 })
    }


}