summaryrefslogtreecommitdiffstats
path: root/lib/src/profile/state.rs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/src/profile/state.rs')
-rw-r--r--lib/src/profile/state.rs30
1 files changed, 28 insertions, 2 deletions
diff --git a/lib/src/profile/state.rs b/lib/src/profile/state.rs
index 33f0bd6..f20135e 100644
--- a/lib/src/profile/state.rs
+++ b/lib/src/profile/state.rs
@@ -6,6 +6,9 @@ use anyhow::Context;
use anyhow::Result;
use tokio::io::AsyncWriteExt;
+use crate::profile::device::Device;
+use crate::profile::device::DeviceSaveable;
+
#[derive(Debug)]
pub struct StateDir(PathBuf);
@@ -39,6 +42,9 @@ pub struct ProfileState {
#[getset(get = "pub")]
keypair: libp2p::identity::Keypair,
+
+ #[getset(get = "pub")]
+ other_devices: Vec<Device>,
}
impl ProfileState {
@@ -46,7 +52,8 @@ impl ProfileState {
Self {
profile_head: None,
profile_name,
- keypair
+ keypair,
+ other_devices: vec![],
}
}
@@ -54,6 +61,11 @@ impl ProfileState {
self.profile_head = Some(cid);
Ok(()) // reserved for future use
}
+
+ pub(super) fn add_device(&mut self, d: Device) -> Result<()> {
+ self.other_devices.push(d);
+ Ok(()) // reserved for future use
+ }
}
impl std::fmt::Debug for ProfileState {
@@ -67,6 +79,7 @@ pub(super) struct ProfileStateSaveable {
profile_head: Option<Vec<u8>>,
profile_name: String,
keypair: Vec<u8>,
+ other_devices: Vec<DeviceSaveable>
}
impl ProfileStateSaveable {
@@ -77,7 +90,14 @@ impl ProfileStateSaveable {
keypair: match s.keypair {
libp2p::identity::Keypair::Ed25519(ref kp) => Vec::from(kp.encode()),
_ => anyhow::bail!("Only keypair type ed25519 supported"),
- }
+ },
+ other_devices: {
+ s.other_devices
+ .iter()
+ .cloned()
+ .map(DeviceSaveable::try_from)
+ .collect::<Result<Vec<_>>>()?
+ },
})
}
@@ -127,6 +147,12 @@ impl TryInto<ProfileState> for ProfileStateSaveable {
let kp = libp2p::identity::ed25519::Keypair::decode(&mut self.keypair)?;
libp2p::identity::Keypair::Ed25519(kp)
},
+ other_devices: {
+ self.other_devices
+ .into_iter()
+ .map(DeviceSaveable::try_into)
+ .collect::<Result<Vec<_>>>()?
+ },
})
}
}