diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2021-12-19 23:08:02 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-12-19 23:08:02 +0100 |
commit | dfe25bddacd903154d73ac5ac7054dd1c3f9d754 (patch) | |
tree | 6ce24bb72f556c9d520500a947994d5d517c337f | |
parent | f1fb13130d471912401d91b284456f325701f6f5 (diff) |
Add Profile::gossip_own_state()
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | lib/src/profile/mod.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/src/profile/mod.rs b/lib/src/profile/mod.rs index d1ab90f..3b1e063 100644 --- a/lib/src/profile/mod.rs +++ b/lib/src/profile/mod.rs @@ -169,6 +169,30 @@ impl Profile { pub fn add_device(&mut self, d: Device) -> Result<()> { self.state.add_device(d) } + + pub async fn gossip_own_state(&self, topic: String) -> Result<()> { + let cid = self.state + .profile_head() + .as_ref() + .ok_or_else(|| anyhow::anyhow!("Profile has no HEAD yet"))? + .to_bytes(); + + let peer_id = self.client + .own_id() + .await? + .to_bytes(); + + self.client + .ipfs + .pubsub_publish(topic, { + crate::gossip::GossipMessage::CurrentProfileState { + peer_id, + cid, + }.into_bytes()? + }) + .await + .map_err(anyhow::Error::from) + } } |